#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin>>T;
  while(T--){
    int N;
    string S;
    cin>>N>>S;
    stack<char>f;
    for(int i=N-1;i>=0;i--){
      if(S[i]=='B'){
        if(i>0&&S[i-1]=='A'&&f.size()&&f.top()=='B'){
          --i;
        }else{
          f.push('B');
        }
      }else{
        if(f.size()&&f.top()=='B'){
          f.pop();
          if(f.empty()||f.top()=='A'){
            f.push('B');f.push('A');
          }
        }else{
          f.push('A');
        }
      }
    }
    while(f.size()){
      cout<<f.top();
      f.pop();
    }
    cout<<'\n';
  }
}