Pousse

Time limit1sMemory limit128 MB

Problem

Pousse (French for "push") is a two-player game played on an $N \times N$ board. The two players, $X$ and $O$, take turns inserting one marker of their own color; $X$ always moves first. The board starts empty. Rows and columns are numbered from $1$ to $N$, starting at the top-left corner:

   1 2 3 4
  +-+-+-+-+
1 | | | | |
  +-+-+-+-+
2 | | | | |
  +-+-+-+-+
3 | | | | |
  +-+-+-+-+
4 | | | | |
  +-+-+-+-+

A marker is inserted by sliding it onto a row from the left or the right, or onto a column from the top or the bottom, so there are $4N$ possible moves. They are written Li, Ri, Ti, Bi, meaning insert into row or column i from the Left, Right, Top, or Bottom respectively.

The square where the marker enters is the end square of that row or column (column $1$ for Li, column $N$ for Ri, row $1$ for Ti, row $N$ for Bi). If that square is empty, the marker simply occupies it. Otherwise, all markers from the entry square up to the first empty square of that row or column are moved one square further along to make room, and the new marker takes the entry square. If the row or column has no empty square, the marker at the far end is pushed off the board and removed from play.

A row or a column is a straight of a given color if all $N$ of its squares hold markers of that color. After each insertion the straights of each color are counted. The moment a move leaves one color with strictly more straights than the other, the game ends and that color's player wins.

Input

The first line contains an integer $N$ ($1 \le N \le 100$). Each of the following lines contains one move, in the notation described above, with no extra spaces or blank lines. Every move in the sequence is valid. The last line of the input is always QUIT.

Output

Play the moves in order. As soon as a move produces a position in which one color has strictly more straights than the other, print X WINS or O WINS (whichever color is dominant) and stop. If the QUIT line is reached before any winner is decided, print TIE GAME.