import collections T = int(input()) for _ in range(T): N=int(input()) S = list(input()) d = collections.deque() d.append('x') d.append('x') bcnt = 0 for s in S[::-1]: d.append(s) if d[-1]=='B' and d[-2]=='B': bcnt+=1 while d[-1]=='A' and d[-2]=='B' and bcnt>=1: d.pop() d.pop() bcnt-=1 ANS = list(d)[::-1] print(''.join(map(str, ANS[:len(ANS)-2])))