#include <stdio.h>
#include <string.h>
#define LEN 101
int main() {
int cnt_str = 0;
scanf("%d", &cnt_str);
for (int i = 0; i < cnt_str; i++) {
char str[LEN];
scanf("%s", str);
int cnt_P = 0, cnt_T = 0, isRight = 1;
int pos_P = 0, pos_T = 0;
for (int i = 0; i < strlen(str); i++) {
if (str[i] == 'P') {
pos_P = i;
cnt_P++;
} else if (str[i] == 'T') {
pos_T = i;
cnt_T++;
} else if (str[i] != 'A') {
isRight = 0;
break;
}
}
if (isRight && cnt_P == 1 && cnt_T == 1) {
int l_A = 0, c_A = 0, r_A = 0;
l_A = pos_P;
c_A = pos_T - pos_P - 1;
r_A = strlen(str) - pos_T - 1;
if (c_A > 0 && l_A * c_A == r_A) {
printf("YES\n");
continue;
}
}
printf("NO\n");
}
return 0;
}