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