//#include #include using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int MAX = 1e9; const int MIN = -1*1e9; const ll MAXLL = 1e18; const ll MINLL = -1*1e18; int main() { int T; cin >> T; for(int t = 0; t < T; t++) { int N; cin >> N; string S; cin >> S; auto solve = [&](int start_idx) { int cnt_A = 0; for(int i = start_idx; i < N; i++) { if(S[i] == 'A') cnt_A++; else break; } if(cnt_A >= 3) { if(start_idx + 1 < N) S[start_idx + 1] = 'B'; } else { bool flag = false; bool active = false; for(int i = start_idx; i < N; i++) { if(S[i] == 'B') { if(!flag) { flag = true; } else { S[i] = 'A'; active = true; } } else { if(active) break; } } } }; if(S[0] == 'A') { solve(0); } else { // Check for leading Bs int cnt_B = 0; for(int i = 0; i < N; i++) { if(S[i] == 'B') cnt_B++; else break; } if(cnt_B == 1) { if(N > 1 && S[1] == 'A') { solve(1); } } } S[0] = 'B'; cout << S << endl; } return 0; }