CF1672B.I love AAAB

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

输入格式

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\texttt{A} and B\texttt{B} .

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

输出格式

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).

输入输出样例

  • 输入#1

    4
    AABAB
    ABB
    AAAAAAAAB
    A

    输出#1

    YES
    NO
    YES
    NO

说明/提示

In the first test case, we transform s1s_1 as such: AABAABAB\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 .

首页