We are at a funfair, where an array of trampolines, named ‘’The Grasshopper Labyrinth’’, catches our attention. As the figure below shows, all of them are labelled with nonnegative integers:
\epsfbox{p11705a.eps}
People are inside, jumping from one trampoline to another, trying to reach the trampoline in the northwest corner, where the exit to the attraction is located. If you reach the exit fast enough, you may win a prize. However, in order to be eligible for the prize, you must abide by the following rule: after leaping from a trampoline labelled with z, you need to get to another one z trampolines away, in the same row or column.
Therefore, your problem is to find the shortest path from any trampoline to the way out, measured by the number of leaps needed. Since the length of the jump from any trampoline is given, it is sufficient to label each trampoline with the direction of the best jump from it.
\epsfbox{p11705b.eps}
For a given starting position, a path is considered shorter than another if it requires a smaller number of jumps; in case of a tie, the path whose first step gets you northmost in the array is to be preferred; and in case of a tie, the one getting you westmost.
Instead of these symbols, we are using the plain text ones: the appropriate cardinal point (‘N’, ‘S’, ‘E’ or ‘W’) for the arrows, ‘X’ for the trampolines without possible escape, and the asterisk ‘*’ for the special trampoline at the upper left position, which represents the exit.
Input
Several cases are given in a single test file. The first line in each test case contains a pair of integers between 1 and 50, separated by a single space; the first is the number of rows and the second the number of columns in the matrix. Then, the entries in the matrix follow, line by line, each element being a nonnegative integer, again separated by single whitespace characters. A 0 x 0 matrix will denote the end of the test cases, and hence should not be analyzed.
Output
The expected output of each data case is a character matrix. Each element is one of the allowed charset, N'',
S’’, E'',
W’’, X'' or
*’’, as described above. The output for each case is followed by a blank line.
Sample Input


Sample Output


Solution
題目描述：
每一個位置的彈簧上會標記一個數字 w，表示可以跳躍至上下左右其中一個方向的 w 距離所在。
求每一個位置下一步的方向，來獲得最短路徑 (跳躍次數) 到最左上角。
題目解法：
題目忘了講到字典順序，如果有相同的情況，則選擇跳躍越左上角越好。

