import java.io.*;
import java.util.*;

public class abbaa_pk implements Runnable {
	public static void main(String[] args) {
		new Thread(new abbaa_pk()).start();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int z = nextInt();
		for (int zz = 0; zz < z; zz++) {
			String s = br.readLine();
			int n = s.length();
			boolean[] fl = new boolean[n];
			if (s.charAt(0) == 'A')
				fl[0] = true;
			if (n > 1) {
				if (s.charAt(1) != s.charAt(0) || (s.charAt(1) == 'A'))
					fl[1] = true;
				for (int i = 2; i < n; i++)
					if (((fl[i - 1]) && (s.charAt(i) == 'A'))
							|| ((fl[i - 2]) && (s.charAt(i) != s.charAt(i - 1))))
						fl[i] = true;
			}
			if (fl[n - 1])
				out.println("YES");
			else
				out.println("NO");
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("abbaa.in"));
			out = new PrintWriter("abbaa.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}