T = int(input()) for _ in range(T): N = int(input()) S = list(input()) S.reverse() A = [] for i in range(N): if len(A) < 2: A.append(S[i]) else: if S[i] == "A" and A[-1] == "B" and A[-2] == "B": A.pop() else: A.append(S[i]) A.reverse() print(*A,sep="")