//g++ 1.cpp -std=c++14 -O2 -I . #include using namespace std; #include #include using namespace atcoder; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using vld = vector; using vvld = vector; using vst = vector; using vvst = vector; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue,less> #define pq_small(T) priority_queue,greater> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) void solve(){ int n; string s; cin>>n>>s; reverse(all(s)); stack st; for(char c:s){ if(st.size()==0||c=='B'){ st.push(c); continue; } if(st.top()=='B'){ if(st.size()==1){ st.push(c); continue; } st.pop(); if(st.top()=='A'){ st.push('B'); st.push(c); continue; } } } while(st.size()!=0){ cout<>t; while(t--){ solve(); } } /* AB hoge... hoge... hogeの頭2文字 A,AA 消さない B,BA,BB 消す ABの時 ABAB hoge... AB hoge... */