#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=200010;
int t,n,m;
int a[N];
void solve()
{
string s; cin>>s;
int a = 0, b = 0;
if(s[s.length() - 1] == 'A') {cout<<"NO\n"; return;}
for(auto it : s)
{
if(it == 'A') a++; else b++;
if(b>a){cout<<"NO\n"; return;}
}
cout<<"YES\n";
}
int main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
cin>>t;
while(t--)
{
solve();
}
return 0;
}