Welcome to ZOJ
 Problem Sets Information Select Problem Runs Ranklist
ZOJ Problem Set - 2693
Procrastination

Time Limit: 10 Seconds      Memory Limit: 32768 KB

Once upon a time, there were two graduate students that were best friends. During their short breaks from research (usually, not longer than several hours), the two students liked to play the game of Procrastination.

The game of Procrastination is for two players (black and white), who take turns moving. The game involves removing cubes from towers. Each cube is either black or white. At the start of the game, these cubes are arranged into 4 towers: each tower is a stack of several cubes. On a player's turn, he can remove any cube that matches his color (the white player removes only white cubes, and the black player only removes black cubes). All the cubes above the chosen cube are also removed from the tower, irrespective of color. For example, suppose a tower is composed of the following cubes (from bottom to top): black, white, black, white. Then, if black removes the bottom-most black cube, he removes the entire tower; black can also take the 3rd cube, removing the 4th cube with it. If white removes the 2nd cube, then only one black cube will remain; white can also take the 4th cube. If a player cannot remove any cubes, he loses.

Having already been trained in the intricacies of the game during their undergraduate years, the two students learned to play the game perfectly, i.e., if a player had a winning strategy, then that player would win the game. However, at some time, they discovered that, for most starting configurations, one of the players has the winning strategy irrespective of which player moves first. They called a configuration a W-configuration if white has a winning strategy irrespective of who moves first, and a B-configuration if black has a winning strategy irrespective of who moves first.

Moreover, the friends noted that some partial configurations are at least as favorable for one player as other configurations. A partial configuration C is defined as a set of 3 towers; note that a partial configuration C together with a 4th tower T forms a complete game configuration, which we denote as (C, T). A formal definition of the notion "at least as favorable" is as follows. A partial configuration C1 (composed of 3 towers) is at least as favorable for white as another partial configuration C2 (also composed of 3 towers) if and only if for any 4th tower T, if (C2, T) is a W-configuration then (C1, T) is also a W-configuration. In other words, there does not exist a 4th tower T such that (C1, T) is not a W-configuration and (C2, T) is a W-configuration.

Given two partial configurations C1 and C2, you are to check whether C1 is at least as favorable for white as the partial configuration C2.

Input

The first line of the input contains an integer, the number of test cases. A test case includes one line with Test N, where N is the current test case number followed by eight lines, specifying the two partial configurations C1 and C2 in this order. Each configuration is specified by four lines.

The first line of the partial configuration contains three numbers: n1, n2, n3 denoting the heights of the three towers of the partial configuration (0 <= n1, n2, n3 <= 50). The second line contains n1 letters (B or W) separated by spaces describing the first tower. The third line contains n2 letters separated by spaces describing the second tower. The fourth line contains n3 letters separated by spaces describing the third tower. A letter W denotes a white cube and the letter B denotes a black cube. Each tower is described in the bottom-to-top order.

Output

For each test case, print on a separate line the test case number and Yes if C1 is at least as favorable for white as the partial configuration C2, and No otherwise.

Sample Input

```2
Test 1
3 3 1
W B B
W B W
B
3 3 3
B W W
B W W
W B B
Test 2
3 3 2
W B B
W B W
B B
3 3 3
B W W
B W W
W B B
```

Sample Output

```Test 1: Yes
Test 2: No
```

Source: MIT Programming Contest, 2005.02.26
Submit    Status