#include<stdio.h>
int main(void) {
int n, k, flag;
char ch;
scanf("%d", &n);
getchar();
while ( n-- ) {
int a[3] = {0};
k = 0, flag = 1;
while ( ( ch = getchar() ) != '\n' ) {
if ( ch == 'A' ) a[k]++;
else if ( ch == 'P' && k == 0 ) k = 1;
else if ( ch == 'T' && k == 1 ) k = 2;
else flag = 0;
}
if ( flag && k == 2 && a[1] && a[0] * a[1] == a[2] ) printf("YES\n");
else printf("NO\n");
}
return 0;
}
网友评论