Codeforces Global Round 20
B
I love AAAB
Codeforces
800
原题
← AC →
翻译中…

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

翻译中…

You are given an initially empty string $s_1$.

翻译中…

You can perform the following operation any number of times:

翻译中…
  • Choose any position of $s_1$ and insert some good string in that position.
翻译中…

Given a string $s_2$, can we turn $s_1$ into $s_2$ after some number of operations?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \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 $s_2$ ($1 \leq |s_2| \leq 2 \cdot 10^5$).

翻译中…

It is guaranteed that $s_2$ consists of only the characters $\texttt{A}$ and $\texttt{B}$.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, print "YES" (without quotes) if we can turn $s_1$ into $s_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 $s_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 $s_1$ as such: $\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$.

翻译中…

In the second and fourth test case, it can be shown that it is impossible to turn $s_1$ into $s_2$.

翻译中…

样例

Input #1
4
AABAB
ABB
AAAAAAAAB
A
Output #1
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
1672B
时间限制
1 s
内存限制
256 MB
标签
构造
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。