You are playing a puzzle game on a grid with $R$ rows and $C$ columns. Each square has a black dot at its centre, and black lines may extend from that dot toward some of its north, east, south, and west neighbours (possibly none of them, possibly all four).
Your piece starts at the centre of the square in row $i_1$, column $j_1$, and you want to move it to the centre of the square in row $i_2$, column $j_2$, using as few turns as possible.
A turn has two parts, and either part may be skipped:
Print the minimum number of turns needed to move the piece from $(i_1, j_1)$ to $(i_2, j_2)$. It is guaranteed that the destination is reachable.
The input contains several test cases.
The first line of each test case contains two integers $R$ and $C$ ($1 \le R, C \le 20$).
The second line contains four integers $i_1$, $j_1$, $i_2$, $j_2$ ($1 \le i_1, i_2 \le R$ and $1 \le j_1, j_2 \le C$): the starting row and column, then the destination row and column.
Each of the next $R$ lines describes one row of the grid, from north (top) to south (bottom). Every such line contains exactly $C$ space-separated tokens describing that row's squares from west (left) to east (right). Each token is one of:
x, meaning the square has no line to any neighbour; orN, E, S, W (each appearing at most once), where N, E, S, W mean the square has a line toward its north, east, south, or west neighbour respectively.It is guaranteed that the piece can be moved from $(i_1, j_1)$ to $(i_2, j_2)$.
The input ends with a line containing 0 0, which must not be processed as a test case.
For each test case, print a single line containing one integer: the minimum number of turns required to move the piece from $(i_1, j_1)$ to $(i_2, j_2)$.
Rotating a square affects only that square, but you may rotate any square on the board (not only the one your piece is on), so you can prepare distant squares in advance. Because rotation and movement can happen in the same turn, aligning a path and walking along it can overlap.
For a $4 \times 2$ board where the piece starts in row 1, column 1 and must reach row 4, column 1, one optimal sequence of 5 turns is: