#include using namespace std; int main() { int T; cin >> T; int N; string S; deque dq; int ds; for(int t = 0; t < T; t++) { cin >> N >> S; for(int i = 0; i < N; i++) { dq.push_back(S[i]); while((int)dq.size() >= 3) { ds = (int)dq.size(); if(dq[ds - 3] == 'A' && dq[ds - 2] == 'B' && dq[ds - 1] == 'B') { dq.pop_back(); dq.pop_back(); dq.pop_back(); dq.push_back('B'); } else break; } } while(!dq.empty()) { cout << dq.front(); dq.pop_front(); } cout << endl; } return 0; }