Mensa Safe

Each grid cell points to another cell; find the start that visits all N*N cells exactly once before repeating, or report none or many.

Medium6GraphSimulationArrayImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Jeyeon wants to join Mensa, and while working through Mensa math quizzes he found out something odd. Mensa members do not use ordinary safes. Their safe has buttons arranged in a grid, and it works like this.

  1. Pick one button, press it, and read the label written on it.
  2. A label is one number followed by one letter. The letter is U (up), D (down), L (left) or R (right), and you move that many cells in that direction.
  3. Press the button you land on, then repeat steps 1 and 2.
  4. If you press a button that was already pressed, the safe stays shut. The moment every button has been pressed once, the safe opens.

Jeyeon liked the mechanism enough to build his own Mensa safe, so he wrote numbers and letters into an N×NN \times N grid however he liked. Once he was done he no longer knew which button to start from. Find the button that opens the safe.

Input

The first line contains the grid size NN (2N10002 \le N \le 1000).

Each of the next NN lines contains NN buttons separated by single spaces. A button is a number of at least 1 written together with one letter, and the letter is one of U, D, L, R. Pressing any button never moves you outside the grid.

Output

If exactly one button opens the safe, print its row number and column number separated by a space. Rows and columns are numbered from 1.

If two or more buttons open the safe, print THIEF LOVE IT!.

If no button opens the safe, print TOO SAFE.