import math from collections import deque,Counter from sys import stdin #sys.setrecursionlimit(10**7) int1=lambda x: int(x)-1 stinput=lambda :stdin.readline()[:-1] ii=lambda :int(stinput()) mi=lambda :map(int, stdin.readline().split()) li=lambda :list(mi()) mi1=lambda :map(int1, stdin.readline().split()) li1=lambda :list(mi1()) mis=lambda :map(str, stdin.readline().split()) lis=lambda :list(mis()) from collections import defaultdict #d=defaultdict(int) #d=defaultdict(lambda:1) mod=10**9+7 Mod=998244353 INF=10**18 ans=0 def solve(): n=ii() s=input() s=list(s) t=[] if s[-1]=='A': t.append(s.pop()) while len(s)>=2 and s[-2]+s[-1]=='AB': t.append(s.pop()) t.append(s.pop()) #print(s,t) d=[] for i in s: d.append(i) if len(d)>=2 and d[-2]+d[-1]=='AB': d.pop() d.pop() ans=d+t[::-1] if len(ans)==0: ans.append('AB') print(''.join(ans)) for _ in range(ii()): solve()