from collections import deque t = int(input()) for _ in range(t): n = int(input()) S = input() ANS = deque() for i in range(n - 1, -1, -1): ANS.appendleft(S[i]) if len(ANS) > 1 and ANS[0] == 'A' and ANS[1] == 'B': if len(ANS) > 2 and ANS[2] == 'B': ANS.popleft() ANS.popleft() print(''.join(ANS))