#include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main() { FAST_IO int T; cin >> T; while (T--) { int N; string S; cin >> N >> S; if (N == 1) { cout << "B" << "\n"; } else { if (S[0] == 'B' && S[1] == 'B') { // none } else if (S[0] == 'B' && S[1] == 'A') { S[1] = 'B'; } else if (S[0] == 'A' && S[1] == 'A') { S[0] = 'B'; S[1] = 'B'; int p = 2; while (p < N && S[p] == 'B') { S[p] = 'A'; } } else { int s = -1, e = N; for (int i = 2; i < N; i++) { if (S[i] == 'B') { if (s < 0) { s = i; } } if (s >= 0 && S[i] == 'A') { e = i; break; } } if (s >= 0) { for (int i = s; i < e; i++) { S[i] = 'A'; } } S[0] = 'B'; } cout << S << "\n"; } } // AAAABBBBAAAABBBB }