t = int(input()) for _ in range(t): n = int(input()) S = input() l = [] for s in S: if s == "A": l.append(s) continue if len(l) < 2: l.append(s) continue # print(l) while len(l) >= 2: if l[-1] == "B" and l[-2] == "A": l.pop() l.pop() else: break l.append(s) # print("ans") print(*l,sep="")