#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++) #define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define TT template template bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; } template bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); srand(time(NULL)); } } io_setup; void solve() { int N; string S; cin >> N >> S; int l = 0; while (l < N && S[l] == 'B') l++; if (l == N) { cout << S << endl; return; } int r = l; while (r < N && S[r] == 'A') r++; if (l >= 2) { cout << S << endl; } else if (l == 1) { S[1] = 'B'; cout << S << endl; } else if (r - l >= 2) { rep(i, l, l + 2) S[i] = 'B'; cout << S << endl; } else { int n = r + 1; while (n < N && S[n] == 'A') n++; while (n < N && S[n] == 'B') { S[n] = 'A'; n++; } rep(i, l, r) S[i] = 'B'; cout << S << endl; } } int main() { int T; cin >> T; while (T--) { solve(); } }