#ifndef SorahISA #define SorahISA #include SorahISA __FILE__ SorahISA void solve() { int N; cin >> N; string S; cin >> S; if (N == 1) { print("B"); return; } if (S.substr(0, 2) == "AA") { ++S[1]; for (int i = 2; i < N and S[i] == 'B'; ++i) --S[i]; } else if (S.substr(0, 2) == "AB") { for (int i = find(2 + ALL(S), 'B') - begin(S); i < N and S[i] == 'B'; ++i) --S[i]; } else if (S.substr(0, 2) == "BA") { --S[0], ++S[1]; for (int i = 2; i < N and S[i] == 'B'; ++i) --S[i]; } else if (S.substr(0, 2) == "BB") { --S[0]; } for (int i = find(ALL(S), 'A') - begin(S); i < N and S[i] == 'A'; ++i) ++S[i]; print(S); } int32_t main() { fastIO(); int t = 1; cin >> t; for (int _ = 1; _ <= t; ++_) { // cout << "Case #" << _ << ": "; solve(); } return 0; } #else #ifdef local #define _GLIBCXX_DEBUG 1 #endif #pragma GCC optimize("Ofast", "unroll-loops") #include using namespace std; // #include // #include using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128; using u128 = unsigned __int128; #define int i64 using f64 = double; using f80 = long double; using f128 = __float128; #define double f80 using pii = pair; template using Prior = std::priority_queue; template using prior = std::priority_queue, greater>; template using MaxHeap = std::priority_queue; template using MinHeap = std::priority_queue, greater>; // #define X first // #define Y second #define eb emplace_back #define ef emplace_front #define ee emplace #define pb pop_back #define pf pop_front #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) #define SZ(x) ((i32)(x).size()) #define popcnt(x) __builtin_popcountll(x) // template struct Vec : vector> { // static_assert(D >= 1, "Vector dimension must be greater than zero!"); // template Vec(int n = 0, Args... args) : vector>(n, Vec(args...)) {} // }; // template struct Vec<1, T> : vector { // Vec(int n = 0, const T& val = T()) : vector(n, val) {} // }; template istream& operator >> (istream &is, vector &vec) { for (auto &x : vec) is >> x; return is; } template ostream& operator << (ostream &os, const vector &vec) { for (size_t i = 0; i < size(vec); ++i) { if (i) os << " "; os << vec[i]; } return os; } #ifdef local #define fastIO() void() #define debug(...) \ _color.emplace_back("\u001b[31m"), \ fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \ _do(__VA_ARGS__), _color.pop_back(), \ fprintf(stderr, "%s", _color.back().c_str()) #define print(...) \ _color.emplace_back("\u001b[36m"), \ fprintf(stdout, "%s", _color.back().c_str()), \ _P(__VA_ARGS__), _color.pop_back(), \ fprintf(stdout, "%s", _color.back().c_str()) deque _color{"\u001b[0m"}; template concept is_string = is_same_v or is_same_v; template concept is_iterable = requires (T _t) { begin(_t); }; template inline void _print_err(T &&_t); template inline void _print_err(T &&_t) requires is_iterable and (not is_string); template inline typename enable_if::type _print_err(const tuple &); template inline typename enable_if::type _print_err(const tuple &_t); template inline typename enable_if::type _print_err(tuple &); template inline typename enable_if::type _print_err(tuple &_t); template ostream& operator << (ostream &os, const pair &_tu); inline void _do() { cerr << "\n"; } template inline void _do(T &&_t) { _print_err(_t), cerr << "\n"; } template inline void _do(T &&_t, U &&..._u) { _print_err(_t), cerr << ", ", _do(_u...); } #else template ostream& operator << (ostream &os, const pair &p) { return os << p.first << " " << p.second; } #define fastIO() cin.tie(0)->sync_with_stdio(0) #define debug(...) void() #define print(...) _P(__VA_ARGS__) #endif inline void _P() { cout << "\n"; } template inline void _P(T &&_t) { cout << _t << "\n"; } template inline void _P(T &&_t, U &&..._u) { cout << _t << " ", _P(_u...); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int getRand(int L, int R) { if (L > R) swap(L, R); return (int)(rng() % ((uint64_t)R - L + 1) + L); } template bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; } template bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; } template void make_unique(vector &vec) { if (not is_sorted(ALL(vec))) sort(ALL(vec)); vec.erase(unique(ALL(vec)), end(vec)); } template void make_psum(vector &vec) { partial_sum(ALL(vec), begin(vec)); } /// below are Fast I/O and _print_err templates /// /* /// Fast I/O by FHVirus /// /// https://fhvirus.github.io/blog/2020/fhvirus-io/ /// #include const int S = 65536; int OP = 0; char OB[S]; inline char RC() { static char buf[S], *p = buf, *q = buf; return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++; } inline int RI() { static char c; int a; while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1); if (c == '-') { a = 0; while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0'; } else { a = c ^ '0'; while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0'; } return a; } inline void WI(int n, char c = '\n') { static char buf[20], p; if (n == 0) OB[OP++] = '0'; p = 0; if (n < 0) { OB[OP++] = '-'; while (n) buf[p++] = '0' - (n % 10), n /= 10; } else { while (n) buf[p++] = '0' + (n % 10), n /= 10; } for (--p; p >= 0; --p) OB[OP++] = buf[p]; OB[OP++] = c; if (OP > S-20) write(1, OB, OP), OP = 0; } /// Fast I/O by FHVirus /// /// https://fhvirus.github.io/blog/2020/fhvirus-io/ /// */ #ifdef local template inline void _print_err(T &&_t) { cerr << _t; } template inline void _print_err(T &&_t) requires is_iterable and (not is_string) { _color.emplace_back(_color.back()); if (_color.back()[3] < '6') ++_color.back()[3]; cerr << _color.back() << "["; for (bool _first = true; auto &_x : _t) { if (!_first) cerr << ", "; _print_err(_x), _first = false; } cerr << "]" << (_color.pop_back(), _color.back()); } template ostream& operator << (ostream &os, const pair &_tu) { _color.emplace_back(_color.back()); if (_color.back()[3] < '6') ++_color.back()[3]; cerr << _color.back() << "("; _print_err(_tu.first), cerr << ", ", _print_err(_tu.second); cerr << ")" << (_color.pop_back(), _color.back()); return os; } template inline typename enable_if::type _print_err(const tuple &) { cerr << ")" << (_color.pop_back(), _color.back()); } template inline typename enable_if::type _print_err(const tuple &_t) { if (!I) { _color.emplace_back(_color.back()); if (_color.back()[3] < '6') ++_color.back()[3]; cerr << _color.back(); } cerr << (I ? ", " : "("), _print_err(get(_t)), _print_err(_t); } template inline typename enable_if::type _print_err(tuple &) { cerr << ")" << (_color.pop_back(), _color.back()); } template inline typename enable_if::type _print_err(tuple &_t) { if (!I) { _color.emplace_back(_color.back()); if (_color.back()[3] < '6') ++_color.back()[3]; cerr << _color.back(); } cerr << (I ? ", " : "("), _print_err(get(_t)), _print_err(_t); } #endif #endif /** * * * * iiiiii iiiiiiiiii iiiiiiiiiiiiii * iiiiiiiiiiiii iiiiiii iiii iiiiiiiiiiiiiii ii iiii * iiiiiiii iiiiiiiii iiii iiii iii iii iiiiiiiiii * iiiiiii iiiiii iiii iiii ii iiiiiiiiii iiii iiii * iiiiii iiiii iiii iiii iii iiii iiiiiiiiiiiiiiiii ii * iiiiii iiiiiii iiiiiii iiiiiiii iii iiiiiiiiiiiiii iii iiii * iiiiii iiiiiii iiiii ii iiii iiiiiiiiiii iiii iii iiii iiii iii * iiiii iiiiiiii ii iiiii iiii iiiiiiiii iii iii iii iii ii iiii * iiiiii iiiiiiii iiiii iiiii iiiiiiiiiiiiiiii iii iii ii iii iii iiii * iiiii iiiiii iiii iiiiii iiiiiii iii iii iiii ii i ii iii iii * iiiiii iiii iiiiiiiiiiiiiii iii iiii iiiii iii ii iii iii ii * iiiii iiiiiiii iiiiiiiiii iiii iiiiiiiii ii iii ii * iiiii iiiiii iiii iiiii iii ii ii i * iiiiii iiiiiiii iiiii iiiii ii ii ii * iiiii iiii iiii iiiiiiiiiiii ii * iii iiii iiii iiiiiiii * iiiii iiii * iiii iiii * iiii iiiii * iii iiiii * iii iiiii * iii iiiiii * iiiiiiiii * iiiiii * * * **/