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

public class abbaa_ats implements Runnable {
	public static void main(String[] args) {
		new abbaa_ats().run();
	}

	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 n = nextInt();
		loop: for (int j = 0; j < n; j++) {
			String s = nextToken();
			assert (s.length() <= (int) 1e5);
			for (int i = 0; i < s.length(); i++) {
				assert (s.charAt(i) == 'A' || s.charAt(i) == 'B');
			}
			// if ((s.charAt(0) == 'B' && (s.length() == 1 || s.charAt(1) ==
			// 'B'))
			// || (s.charAt(s.length() - 1) == 'B' && s.charAt(s.length() - 1)
			// ==
			// 'B')) {
			// out.println("NO");
			// return;
			// }
			for (int i = 0; i < s.length();) {
				if ((i + 1 < s.length())
						&& (s.charAt(i) == 'B' && s.charAt(i + 1) == 'A' || s
								.charAt(i + 1) == 'B' && s.charAt(i) == 'A')) {
					i += 2;
				} else if (s.charAt(i) == 'A') {
					i++;
				} else {
					out.println("NO");
					continue loop;
				}
			}
			out.println("YES");
		}
	}

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

			solve();

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