#include<iostream>
#include<string>
using namespace std;
int main()
{
int num;
string str;
cin >> num;
for (int i = 0; i < num; i++)
{
cin >> str;
int cnt = 0,cnt1,cnt2;
bool flag1 = false,flag2=false,flag3=false;
for (int j = 0; j < str.size(); j++)
{
if (str[j]=='A')
{
cnt++;
}
else if (str[j]=='P'&&flag1==false)
{
cnt1 = cnt;
cnt = 0;
flag1 = true;
}
else if (str[j] == 'T'&&flag2 == false)
{
cnt2 = cnt;
cnt = 0;
flag2 = true;
}
else
{
flag3 = true;
break;
}
}
if (cnt2==0 && flag3 == false)
{
cout << "NO" << endl;
}
else if (cnt1*cnt2==cnt && flag3 == false)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
system("pause");
return 0;
}
网友评论