/** author: shobonvip created: 2025.12.26 15:22:59 **/ #include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) #define all(v) v.begin(), v.end() template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } string alice_choice(string s) { int n = (int)s.size(); if (n <= 2) return s; if (s[0] == 'A') { if (s[1] == 'A' && s[2] == 'A') { s[1] = 'B'; return s; } else { int mode = 0; rep(i,0,n) { if (mode == 0 && s[i] == 'B') { mode = 1; } else if (mode == 1 && s[i] == 'B') { mode = 2; s[i] = 'A'; } else if (mode == 2 && s[i] == 'B') { s[i] = 'A'; } else if (mode == 2 && s[i] == 'A') { mode = 3; } } return s; } } else { if (s[1] == 'A') { return 'B' + alice_choice(s.substr(1, n-1)); } else { s[0] = 'A'; return s; } } } string bob_choice(string s) { int n = (int)s.size(); int mode = 0; rep(i,0,n) { if (mode <= 1 && s[i] == 'A') { mode = 1; s[i] = 'B'; }else if (mode == 1 && s[i] == 'B') { mode = 2; } } return s; } void solve() { int n; cin >> n; string s; cin >> s; string t = alice_choice(s); string ans = bob_choice(t); cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--) solve(); }