CF2178A.Yes or Yes

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

Yes or Yes

Last Christmas, your friend Fernando gifted you a string ss consisting only of the characters Y and N, representing "Yes" and "No", respectively.

You can repeatedly apply the following operation on ss:

  • Choose any two adjacent characters and replace them with their logical OR.

Formally, in each operation, you can choose an index ii (1is11 \leq i \leq |s|-1), remove the characters sis_i and si+1s_{i+1}, then insert:

  • A single Y if at least one of sis_i or si+1s_{i+1} is Y;
  • A single N if both sis_i and si+1s_{i+1} are N.

Note that after each operation, the length of ss decreases by 11.

Unfortunately, Fernando does not want you to combine "Yes OR Yes", as he has experienced trauma relating to a certain song.

Determine whether it is possible to reduce ss to a single character by repeatedly applying the operation above, without ever combining two Y's.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The only line of each test case contains the string ss (2s1002\le |s|\le 100). It is guaranteed that si=Ys_i = \mathtt{Y} or N.

Output

For each test case, print "YES" if the string can be reduced to a single character by repeatedly applying the described operation, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, you cannot combine s1s_1 and s2s_2 since they are both Y. Thus, the answer is NO.

In the third test case, the following is a valid sequence of operations: \underline{NN}Y}\to\mathtt{\underline{NY}}\to\mathtt{Y. Thus, the answer is YES.

In the fourth test case, there are two possibilities for the first operation: YY\underline{YN}Y}\to \mathtt{YYYY or YYY\underline{NY}}\to \mathtt{YYYY. However, in either case, it is not possible to perform any more operations without combining two Y's. Thus, the answer is NO.

In the fifth test case, the following is a valid sequence of operations: N\underline{NN}NN}\to\mathtt{\underline{NN}NN}\to\mathtt{N\underline{NN}}\to\mathtt{\underline{NN}}\to\mathtt{N. Thus, the answer is YES.

Samples

7
YY
NN
NNY
YYYNY
NNNNN
YYYYYY
YNNNNN
NO
YES
YES
NO
YES
NO
YES

在线编程 IDE

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