CF1672B.I love AAAB

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

I love AAAB

Let's call a string good if its length is at least 22 and all of its characters are A except for the last character which is B. The good strings are AB,AAB,AAAB,\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots. Note that B is not a good string.

You are given an initially empty string s1s_1.

You can perform the following operation any number of times:

  • Choose any position of s1s_1 and insert some good string in that position.

Given a string s2s_2, can we turn s1s_1 into s2s_2 after some number of operations?

Input

Each test contains multiple test cases. The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single string s2s_2 (1s221051 \leq |s_2| \leq 2 \cdot 10^5).

It is guaranteed that s2s_2 consists of only the characters A and B.

It is guaranteed that the sum of s2|s_2| over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, print "YES" (without quotes) if we can turn s1s_1 into s2s_2 after some number of operations, and "NO" (without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

Note

In the first test case, we transform s1s_1 as such: $\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$.

In the third test case, we transform s1s_1 as such: AAAAAAAAB\varnothing \to \color{red}{\texttt{AAAAAAAAB}}.

In the second and fourth test case, it can be shown that it is impossible to turn s1s_1 into s2s_2.

Samples

4
AABAB
ABB
AAAAAAAAB
A
YES
NO
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验