t=int(input()) ns=[] for _ in range(t): n=int(input()) s=input() ns.append([n,s]) for n,s in ns: # Bの前にあるABは全て消す if n<=2: print(s) continue ans=[] s=list(s) i=0 ans.append(s.pop()) ans.append(s.pop()) while s: if len(ans)>=2 and ans[-1]=="B" and ans[-2]=="B" and s[-1]=="A": s.pop() ans.pop() else: ans.append(s.pop()) ans.reverse() print("".join(ans))