This page is still under construction.

Parts of this page are still being built. What you see may change.

Chomp

Time limit1sMemory limit128 MB

Summary
Decide whether each 3-row Chomp position is winning and output a move to a losing position.
Level

Medium6 of 10

Topics
Game theory, Dynamic programming
Solved
No attempts yet

Problem

Chomp is a game for two players, played on a rectangular chocolate bar cut into square cells. On a turn a player picks one remaining cell and eats it, together with every remaining cell whose column number is at least as large and whose row number is at least as large. The cell in the bottom left corner is poisoned, and the player who is forced to eat it loses.

Columns are numbered 1,2,3,…1, 2, 3, \dots from the left and rows are numbered 1,2,31, 2, 3 from the bottom, so the poisoned cell is the one in column 11, row 11.

A position is a winning position if some move leaves the opponent in a losing position. A position is a losing position if every move either eats the poisoned cell or leaves the opponent in a winning position. For example, the 1×11 \times 1 board and the L shapes whose two arms have equal length are losing positions, because the opponent can copy whatever the player to move does. The 3×33 \times 3 board, an L whose arms have different lengths, and a single row of nn cells are winning positions.

This problem asks you to solve Chomp on a board with 33 rows and at most 100100 columns. Eating a cell always removes everything above it and to its right, so the cells left in a row are the leftmost ones, and any position that can arise is described by the number pp of cells left in the bottom row, the number qq left in the middle row and the number rr left in the top row, with 100≥p≥q≥r≥0100 \ge p \ge q \ge r \ge 0.

Write a program that decides, for each given position, whether it is a winning or a losing position, and for a winning position finds a cell to eat next that leaves the opponent in a losing position.

Input

The first line contains the number of data sets PP. (1≤P≤10001 \le P \le 1000)

Each of the next PP lines holds one data set. A line contains the data set number KK, the number pp of cells in the bottom row, the number qq of cells in the middle row and the number rr of cells in the top row, separated by single spaces, with 100≥p≥q≥r≥0100 \ge p \ge q \ge r \ge 0. The data sets are independent.

Output

Print one line for each data set.

If the position is a losing position, print the data set number KK, a single space, and the capital letter L.

If the position is a winning position, print the data set number KK, the capital letter W, and then the column number and the row number of the cell to eat next, separated by single spaces. When several moves leave the opponent in a losing position, print the one with the smallest column number, and among those the one with the smallest row number.

Examples2

  1. Example 1

    Input
    4
    1 3 3 3
    2 3 1 0
    3 3 2 0
    4 97 64 35
    
    Expected output
    1 W 2 2
    2 W 3 1
    3 L
    4 W 51 1
    
  2. Example 2

    Input
    4
    1 3 2 1
    2 3 3 1
    3 4 3 2
    4 6 5 3
    
    Expected output
    1 W 1 3
    2 W 2 2
    3 W 1 3
    4 W 1 3