Under construction

Still being built. Things may change

The Puzzle Game Luminous Met on His Adventure

Time limit4sMemory limit1024 MB

Summary
Given a grid of light and dark traps, decide whether all traps can be removed by pressing dark cells that flip their neighbors, and print a press order if so.
Level

Medium7 of 10

Topics
Graph, Topological sort, Matrix
Solved
No attempts yet

Problem

The sorcerer Luminous, master of light and darkness, is on an adventure. Right now he is trapped in a labyrinth full of traps. He took a shortcut to escape quickly, and at that moment he ran into a trap field called a puzzle game.

He had a reason to escape fast, so he walked up to the trap field to solve the puzzle game. Then a loud noise sounded and a hologram appeared. It showed a shrinking timer and the message "Every skill you have is sealed except one." Luminous shouted "Anti Magic Shell!" but the cry went nowhere. In the end he had to choose between solving the puzzle and giving up the shortcut.

The puzzle game is played on an N×MN \times M grid. Each cell holds a light trap or a dark trap. To pass safely, he must use skills to remove every trap on the grid.

The only skill Luminous has not had sealed is the Light Punishing Resonator. It can only target dark traps. When used, the targeted dark trap is removed, and the traps in the orthogonally adjacent cells have their types flipped.

The labyrinth holds an endless number of traps, so he must solve KK puzzles of this kind in total.

Given the state of each puzzle, determine whether Luminous can solve it, and if he can, show how.

Input

The input consists of several puzzles. The first line contains KK, the number of puzzles to solve. The state of each puzzle follows in order.

The first line of each puzzle contains NN and MM, the number of rows and columns, separated by a space.

The next NN lines each contain a string of length MM made of L and D. If the jj-th character of line i+1i+1 is L, cell (i,j)(i, j) has a light trap. If it is D, cell (i,j)(i, j) has a dark trap.

Output

For each puzzle, print whether it can be solved, and if it can, print the method.

If Luminous can solve the puzzle, print Solve. The following lines list the cells where he must use the Light Punishing Resonator, in order, over NMNM lines. If the trap at row ii, column jj must be targeted by the kk-th use of the Resonator, print ii and jj separated by a space on line k+1k+1.

If he cannot solve the puzzle, print Run.

If several methods solve a puzzle, printing any one of them is enough.

Constraints

  • 1≤N,M≤3,0001 \le N, M \le 3{,}000
  • 1≤K≤2,000,0001 \le K \le 2{,}000{,}000
  • In all puzzles, the sum of NMNM does not exceed 10,000,00010{,}000{,}000.

Hint

TMI: Anti Magic Shell is Luminous's skill that creates a barrier which ignores severe status effects.

Examples1

  1. Example 1

    Input
    2
    2 2
    DD
    DD
    2 2
    LL
    LL
    
    Expected output
    Solve
    1 1
    2 2
    1 2
    2 1
    Run