You and your friends got bored of chess and backgammon, so you made a new game. It is a single player game played with one backgammon die (the singular of dice) on a board that looks like a chess board.
The board has N rows and M columns. Every cell is either empty or holds one digit from 0 to 9. A die with the numbers 1 to 6 on its six faces sits on the starting cell, and the edges of its bottom face are aligned with the axes of the board. Your goal is to move it to the target cell.
Rows are numbered 1 to N from top to bottom, and columns 1 to M from left to right. Forward is the direction of decreasing row number, backward the direction of increasing row number, right the direction of increasing column number, and left the direction of decreasing column number.
The initial orientation of the die is given by a string S, a permutation of the digits 1 to 6. Its characters give the number on the right, left, forward, backward, top and bottom face, in that order.
The die moves under these rules.
136425 and you move the die to the cell on its right, the right face becomes the bottom face in the new cell, so the orientation becomes 256431.Given the board, the starting cell, the target cell and the initial orientation of the die, find the maximum score you can end up with after moving the die from the starting cell to the target cell under these rules.
The first line contains a single integer T, the number of test cases (1≤T≤200). The specifications of T test cases follow.
Each test case is given in N+2 lines. The first line contains two integers N and M (1≤N,M≤10), the number of rows and the number of columns of the board. The second line contains the string S describing the initial orientation of the die on the starting cell. Each of the remaining N lines contains M characters, where the j-th character of the i-th line is the value of the cell in row i, column j. Each character is one of the following.
. is an empty cell.S is the starting cell, which appears exactly once on the board.T is the target cell, which appears exactly once on the board.0 to 9 is the value written in that cell.For each test case, print one line containing one of these.
Impossible if you can not reach the target cell from the starting cell.Infinity if your final score has no upper limit and you can raise it without end.