Move on Dice#5840

Move on Dice

5 seconds
64 megabytes
Very easy

There is a cube on a rectangular map with a grid of rows and columns. Two special squares are marked on the map: a start and a goal. The cube is initially on the start square. Let's roll it to take it to the goal square. Rolling the cube means selecting one of four edges touching the map and pushing the cube over that edge, without detaching it from the map. Thus, you can move the cube in one of four directions.

Directions in which you can roll the cube are limited per square. Each square has an instruction given by a character as follows:

'+' — all directions allowed

'|' — only vertical

'-' — only horizontal

'<' — only left

'>' — only right

'^' — only up

'v' — only down

'.' — none

Regardless of instructions, it is prohibited to roll the cube outside the map.

On each face of the cube, there is a string. Output the concatenation of strings written on the top face during the sequence of rolls from the start square to the goal square. As there may be many such paths, choose the minimal string in lexicographic order.

There may be cases where no path exists from the start to the goal, or where you can make the minimal lexicographic string infinitely long.

Input

A data set has the following format:

C_{11}\ \ldots\ C_{1W}

C_{H1}\ \ldots\ C_{HW}

T_1

T_6

R_S\ C_S

R_D\ C_D

The first line contains two integers (1 \leq H \leq 12) and (1 \leq W \leq 12), the number of rows and columns, respectively. The next lines describe the map. The -th character of the -th line gives the instruction for the square at row (from top) and column (from left).

The next lines describe the strings on each face of the cube. All strings are non-empty and at most characters long, consisting only of uppercase letters or digits. The cube faces are as shown in Figure 1. The cube starts on the start square in the orientation where face No. 1 is on top and the top of face No. 1 points toward the first (top) row.

Figure 1 — cube net

The last two lines each contain two integers, indicating the row and column of the start square and the goal square, in that order. The start and goal are always different.

Output

Print the lexicographically minimal string in one line. If there is no path, print no in one line. If the minimal string could be made infinitely long, print infinite in one line.

Examples

Example 1

Loading
Loading