#include using namespace std; int main() { int t; cin >> t; while (t--) { int N; string S; cin >> N >> S; vector c(N + 1, 0); int x = N - 1; while (0 < x && S[x] == 'A') { x--; } for (int i = x; i > 0; i--) { c[i - 1] = c[i]; if (S[i] == 'A') { c[i - 1]--; } else { c[i - 1]++; } } int cnt = 0; for (int i = 0; i < N; i++) { if (S[i] == 'A') { if (c[i] <= 1) { cout << 'A'; } else { cnt++; } } else { if (cnt > 0) { cnt--; } else { cout << 'B'; } } } cout << endl; } }