def solve(n,s): ans=[] for i in range(n): if ans: if ans[-1]=='A' and s[i]=='B': if i+1=2 and ans[-2]=='A' and ans[-1]=='B': ans.pop() ans.pop() else: ans.append(s[i]) else: ans.append(s[i]) else: ans.append(s[i]) print(*ans,sep='') t=int(input()) for _ in range(t): n=int(input()) s=input() solve(n,s)