Input consists of a number of test cases. The first line of each test case contains the two integers
R and
C, separated by spaces, with 1 <=
R, C <= 20.
The next line contains the integers
i1, j1, i2, j2, separated by spaces, with 1 <=
i1, i2 <=
R and 1 <=
j1, j2 <=
C.
The following
R lines of input each contain one row of the grid, from north to south. Each of these lines contains exactly
C strings of letters, separated by spaces, that correspond to squares of the grid, from west to east. Their format is as follows:
- If the string is the single character x, then the square does not contain a line to any of its neighbours.
- Otherwise, the string contains some of the characters N, E, S, W, which indicate that a black line extends from this square's centre in the direction of its north, east, south, or west neighbour, respectively. No character will appear in the string more than once.
It is guaranteed that it is possible to move your playing piece from (
i1, j1) to (
i2, j2).
Input is terminated by a line containing 0 0. These zeros are not a test case and should not be processed.