t = int(input()) for _ in range(t): n = int(input()) S = input() ANS = '' for i in range(n - 1, -1, -1): ANS = S[i] + ANS if ANS[:2] == "AB": if len(ANS) > 2 and ANS[2] == 'B': ANS = ANS[2:] print(ANS)