Game of Blocks

SOHA and TARA are playing Game of Blocks. ‘Game of Blocks’ is a two player game played on a 4 × 4 board. At the start of the game, each cell contains a piece colored red or blue. The two players make moves alternately - SOHA, being player 1, makes the first move. In each move, a player chooses a colored cell (that is a cell with a blue or a red piece in it). After making a move, all the reachable cells from that selected cell vanishes. Two cells are reachable if you can start from one and end on the other by making moves in the direction up, down, left or right and all the pieces in the path has the same color. After each move, all the pieces will come down to fill the empty spaces. Consider an initial grid shown above. The blue pieces have white cen- ters to differentiate them from the red pieces in order to facilitate the colored blind people. Say, SOHA makes a move by selecting the cell at row 2 and column 3 or in other words cell (2, 3). The diagrams below shows what happens to the pieces after the move is made. The player to remove the last piece wins the game. If both of the players play perfectly, can you determine whether SOHA will be able to win the game? If a player can win, (s)he will try to finish the game in minimum number of moves possible. However, if a player finds (s)he has no way to win, (s)he will make moves in order to delay the game as long as possible. Input The first line of input is an integer T (T ≤ 1000) that indicates the number of test cases. Each case consists of 4 lines with 4 characters in each. The characters are ‘B’ or ‘R’ to indicate blue and red pieces respectively. There is a blank line after each case. Output For each case, output the case number first. If SOHA can win the game, print ‘win X’, otherwise print ‘loss X’ where X indicates the total number of moves before all the pieces vanishes. Sample Input 3 BBBB BBBB

2/2 BBBB BBBB BBBB RRRR BBBB RRRR BRBR BRBR BRBR BRBR Sample Output Case 1: win 1 Case 2: win 3 Case 3: loss 4