On an arrow board, choose K non-last-column cells so that a robot starting anywhere in column 1 passes through exactly one of them or loops forever.
Hard8GraphGreedyImplementationNo attempts yetTime limit1sMemory limit512 MBHansel and Gretel are playing a game called "Arrows" on a board with R rows and S columns. Every field of the board holds exactly one arrow, which points in one of the four directions: up, down, left, or right.
Hansel moves first: he colours exactly K fields that are not in the last column. Gretel then places a robot on any field of the first column. From then on the robot moves by itself, each time stepping to the field that the arrow of its current field points to. When the robot reaches a field in the last column, it stops and the game ends.
The winner is decided as follows.
The fields the robot passes through include its starting field, every field it moves onto during the game, and the field where it is when the game ends. The arrows are drawn so that the robot never leaves the board.

Determine whether Hansel can colour fields so that he wins no matter where Gretel places the robot. If he can, output the K fields he colours.
The first line contains the integers R, S, and K (1≤R×S≤1000000, 1≤K≤50).
Each of the next R lines contains S characters, each one of 'L', 'R', 'U', and 'D', giving the direction of the arrow in the corresponding field: L is left, R is right, U is up, and D is down.
If Hansel cannot ensure his victory, output -1.
Otherwise, output the K fields he colours, one per line. Each line contains two integers A and B (1≤A≤R, 1≤B≤S) separated by a space: the row and the column of the field. All coloured fields must be different. Output the fields in increasing order of row, and fields in the same row in increasing order of column. This order is called row-major order.
Hansel can often win with several colourings, so output the one defined by the following rule.
In the first sample, if Hansel colours the field (1, 2), the robot passes through it no matter where Gretel places it, so Hansel wins. Colouring the field (4, 2) also wins, but the output rule gives the answer (1, 2).