N=int(input()) for i in range(N): S=list(map(str,input().split("AB"))) print("".join(S))