Problem E - Tile Game

John has bought a new game that is driving him crazy. The game proposes simple puzzles where the player has to find a way to transform a tilled square into another tilled square pressing its tiles. Each tile can be either white or black and each puzzle has an initial configuration, a goal configuration and a set of rules. These rules allow users to change tiles from black to white and vice-versa. The rules are also very simple. Each tile has a different transformation rule. By clicking a tile, its transformation rule is applied to the whole puzzle. A transformation rule states, for each tile, if it remains unchanged (X), changes to either white (W) or black (B) or if it flips (F) (see Figure 1). Flipping means that the tile becomes white if it was black and black if it was white.

Figure 1. Example game.

A solution to a certain puzzle is the set of tiles that the player needs to press in order to go from the initial state to the goal state. The lower the number of tile presses the user takes the better the score. Figure 2 represents a possible solution for the puzzle just presented..

Figure 2. Example solution.

John is desperate to beat his younger brother high-scores and he asked for your help. Your task is to develop a program that given a puzzle of size D outputs the fastest way to solve it.

Input

Each input file will contain the description of a puzzle with the first line containing a single integer representing its dimension D. The next D lines will contain the initial configuration of the puzzle. Each one of these lines will be composed of D characters with the values B or W representing the type of each tile. The next D lines will contain the expected final result of the puzzle using the same notation as for the initial configuration. The remaining of the file will contain the puzzle rules. These will use D × D lines (D lines for each one of the D transformation rules). For each tile there will be D lines containing its transformation rules. Each transformation rule will have D lines. Each one of these lines will be composed of d characters with the values X, F, B, or W (Keep unchanged, flip, change to black or change to white).

Output

The output will contain one single line containing the optimum solution to the puzzle. The optimum solution is the one that uses less tile presses. If more than one optimum solution exists the program should output the solution that comes lexicographically first. The solution should be printed as a sequence of space separated numbers from 1 to D × D representing the tiles to be clicked. With tile number 1 being the one at the top left and tile number D × D being the one at the bottom right. If no solution exists the program should output a single line containing "No solution". If the initial and final configuration are the same the program should output a single line containing "No moves required".

Constraints

1D3

Sample Input 1

2
BB
WW
WW
BB
WW
BX
XW
BF
XB
FW
WW
BW

Sample Output 1

1 2

Sample Input 2

2
BB
WW
WW
BB
WW
BX
XW
BW
XB
FW
WW
BW

Sample Output 2

No solution