import sys input = sys.stdin.readline T=int(input()) for tests in range(T): N=int(input()) S=input().strip() T=[] for s in S[::-1]: if s=="A" and len(T)>=2 and T[-1]=="B" and T[-2]=="B": T.pop() continue else: T.append(s) print("".join(T[::-1]))