#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main()
{
int n = 0;
bool flag = false;
cin >> n;
string a = "";
int pPosition = 0;
int tPosition = 0;
int numP = 0;
int numT = 0;
bool * ans = new bool[n] {false};
for (int i = 0; i < n; i++)
{
flag = false;
numP = 0;
numT = 0;
cin >> a;
for (int j = 0; j < a.length(); j++)
{
if( !(a[j] == 'P' || a[j] == 'A' || a[j] == 'T'))
{
flag = true;
break;
}
if (a[j] == 'P')
{
if (numP > 1)
{
flag = true;
break;
}
numP++;
pPosition = j;
}
if (a[j] == 'T')
{
if (numT > 1)
{
flag = true;
break;
}
numT++;
tPosition = j;
}
}
if (!flag)
{
if (pPosition < tPosition-1)
{
if (pPosition == tPosition - 2 & pPosition == a.length() - tPosition - 1)
{
ans[i] = true;
continue;
}
if (pPosition != tPosition - 2)
{
int nA = tPosition - pPosition - 1;
if (pPosition*nA == a.length() - tPosition - 1)
{
ans[i] = true;
continue;
}
}
}
else
ans[i] = false;
}
else
ans[i] = false;
}
for (int i = 0; i < n; i++)
{
if (ans[i])
cout << "YES" << endl;
else
cout << "NO" << endl;
}
system("pause");
}
#include<math.h>
#include<string>
using namespace std;
int main()
{
int n = 0;
bool flag = false;
cin >> n;
string a = "";
int pPosition = 0;
int tPosition = 0;
int numP = 0;
int numT = 0;
bool * ans = new bool[n] {false};
for (int i = 0; i < n; i++)
{
flag = false;
numP = 0;
numT = 0;
cin >> a;
for (int j = 0; j < a.length(); j++)
{
if( !(a[j] == 'P' || a[j] == 'A' || a[j] == 'T'))
{
flag = true;
break;
}
if (a[j] == 'P')
{
if (numP > 1)
{
flag = true;
break;
}
numP++;
pPosition = j;
}
if (a[j] == 'T')
{
if (numT > 1)
{
flag = true;
break;
}
numT++;
tPosition = j;
}
}
if (!flag)
{
if (pPosition < tPosition-1)
{
if (pPosition == tPosition - 2 & pPosition == a.length() - tPosition - 1)
{
ans[i] = true;
continue;
}
if (pPosition != tPosition - 2)
{
int nA = tPosition - pPosition - 1;
if (pPosition*nA == a.length() - tPosition - 1)
{
ans[i] = true;
continue;
}
}
}
else
ans[i] = false;
}
else
ans[i] = false;
}
for (int i = 0; i < n; i++)
{
if (ans[i])
cout << "YES" << endl;
else
cout << "NO" << endl;
}
system("pause");
}