t = int(input()) for _ in range(t): n = int(input()) s = input() st = [] for c in s: if c == 'B': while len(st) >= 2 and st[-1] == 'B' and st[-2] == 'A': st.pop() st.pop() st.append(c) print(*st, sep='')