t = int(input()) for _ in range(t): n = int(input()) S = input() ANS = '' res = 0 for i in range(n): s = S[i] if s == 'A': ANS += s elif s == 'B' and len(ANS) > 0 and ANS[-1] == 'A': if i < n - 1 and ANS[:-1] + S[i + 1] > ANS + S[i:i + 2]: ANS = ANS[:-1] else: ANS += s else: ANS += s res = 0 for i in range(0, len(ANS), 2): if ANS[i:i + 2] == 'AB': res += 2 else: break if len(ANS) != res: ANS = ANS[res:] print(ANS)