T = int(input()) for _ in range(T): N = int(input()) S = input().strip() ans = [] for i in range(N-1,-1,-1): a = S[i] if a=="A" and len(ans)>1 and ans[-1]=="B" and ans[-2]=="B": ans.pop() else: ans.append(a) print("".join(ans[::-1]))