#include <bits/stdc++.h>
using namespace std;
int main() {
    int T; cin >> T;
    while (T--) {
        int N; cin >> N;
        string S; cin >> S;
        stack<char>C;
        C.push(S.back());
        S.pop_back();
        while (!S.empty()) {
            if (C.top() == 'B' && S.back() == 'A') {
                if ((int)C.size() == 1) {C.push('A');S.pop_back();continue;}
                C.pop();
                if (C.top() == 'A') {C.push('B'); C.push('A');}
            }
            else C.push(S.back());
            S.pop_back();
        }
        while (!C.empty()) {
            cout << C.top();
            C.pop();
        }
        cout << endl;
    }
}