import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner inScanner = new Scanner(System.in);
int a = inScanner.nextInt();
for (int i = 0; i < a; i++) {
String strsString = inScanner.next();
int flag1 = 0,flag2 = 0,flag3 = 0,p = 0,t = 0,j = 0;
for ( j = 0; j < strsString.length(); j++) {
if (strsString.charAt(j) != 'P' && strsString.charAt(j) != 'T' && strsString.charAt(j) != 'A') {
System.out.println("NO");
flag3 = 1;
break;
}
if (strsString.charAt(j) == 'P') {
flag1++;
p = j+1;
}else if (strsString.charAt(j) == 'T') {
flag2++;
t = j+1;
}
}
if (flag3 != 1) {
if (flag1 != 1 || flag2 != 1 || t-p <= 1) {
System.out.println("NO");
}else if (strsString.length()-t != (p-1)*(t-p-1)) {
System.out.println("NO");
}else {
System.out.println("YES");
}
}
}
inScanner.close();
}
}