luogu#P8144. [JRKSJ R4] BBWWBB

[JRKSJ R4] BBWWBB

Problem Description

There are 66 pieces on a number line. Initially, the ii-th piece is placed at aia_i, and aa is strictly increasing.

Among them, pieces 1,2,5,61,2,5,6 are black, and pieces 3,43,4 are white.

During the game, any number of pieces of the same color may exist on the same position at the same time.

There are two sides: Black and White. They take turns to operate:

  • Choose a piece of your own color and move it one step to the left or to the right.
  • If the destination position contains an opponent's piece and contains exactly 11 such piece, then you may move there and remove that piece at the same time.
  • If the destination position contains multiple opponent pieces, then you may not move to that position.
  • When a side has no piece that can be moved, that side loses and the game ends.

Both sides aim, under the premise that they do not lose, to make the opponent lose as much as possible. Both sides use optimal strategies.

Given which side moves first and the positions of all pieces, determine whether the game will continue forever.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases.

The following TT lines each describe one test case.

Each test case starts with a character cc, either B\texttt B or W\texttt W. c=Bc=\texttt B means Black moves first, and c=Wc=\texttt W means White moves first. Then 66 integers are given, representing a16a_{1\dots 6}.

Output Format

For each test case, output one line containing Yes or No. Yes means the game will continue forever, and No otherwise.

2
B 1 3 4 6 8 9
W 1 3 4 6 8 9
No
Yes

Hint

Constraints

For 15%15\% of the testdata, c=Bc=\texttt B.
For 100%100\% of the testdata, T105T\le10^5, ai109|a_i| \le 10^9, c{B,W}c\in\{\texttt B,\texttt W\}. It is guaranteed that aa is strictly increasing.

Sample Explanation

For the 11-st test case, one possible sequence of positions is as follows:

B:
1 4 6 8 9
B B W B B
W:
1 4 5 8 9
B B W B B
B:
1 5 8 9
B B B B

For the 22-nd test case, one possible sequence of positions is as follows:

W:
1 3 6 8 9
B W W B B
B:
1 3 6 8 8
B W W B B
W:
1 3 5 8 8
B W W B B
B:
1 3 5 7 8
B W W B B
W:
1 3 4 7 8
B W W B B
B:
1 3 4 7 7
B W W B B
W:
1 3 3 7 7
B W W B B
B:
1 3 3 6 7
B W W B B
W:
1 2 3 6 7
B W W B B
B:
2 3 6 7
B W B B
W:
2 6 7
W B B

After that, White controls W to move one step to the left each time. No matter how Black operates, the game can continue forever.

Translated by ChatGPT 5