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