#include #include //小数点出力用 //cout << fixed << setprecision(10) << ans; #include #include #include #include #include #include #include #include using ll = long long; using namespace std; #define modPHash (ll)((1LL<<61)-1) #define modP (ll)998244353 bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); } int clk4(int num) { return (num - 2) * (num % 2); } void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; while (T--) { int N; cin >> N; string S; cin >> S; if (N == 1) { cout << "B\n"; } else if(N == 2){ cout << "BB\n"; } else { if (S.substr(0,3) == "AAA") { cout << "BBA"; cout << S.substr(3) << "\n"; } else if (S.substr(0, 3) == "AAB") { int i = 2; while (i != N && S[i] == 'B') { S[i] = 'A'; i++; } S[0] = 'B'; S[1] = 'B'; cout << S << "\n"; } else if (S.substr(0, 3) == "ABA") { int i = 2; while (i != N && S[i] == 'A')i++; while (i != N && S[i] == 'B') { S[i] = 'A'; i++; } S[0] = 'B'; cout << S << "\n"; } else if (S.substr(0, 3) == "ABB") { int i = 2; while (i != N && S[i] == 'B') { S[i] = 'A'; i++; } S[0] = 'B'; cout << S << "\n"; } else if (S.substr(0, 3) == "BAA") { cout << "BB"; cout << S.substr(2) << "\n"; } else if (S.substr(0, 3) == "BAB") { int i = 2; while (i != N && S[i] == 'B') { S[i] = 'A'; i++; } S[0] = 'B'; S[1] = 'B'; cout << S << "\n"; } else if (S.substr(0, 3) == "BBA") { cout << S << "\n"; } else if (S.substr(0, 3) == "BBB") { cout << S << "\n"; } } } }