Hiking

No attempts yetTime limit3sMemory limit256 MB

Problem

You like adventure, and hiking is one of your favorite hobbies. A novice is joining you on this trip, so you want to pick the easiest route on the map of the area.

The hiking area is a grid with hh rows and ww columns. Each cell is identified by its row number and column number, where (0,0)(0, 0) is the top-left cell and (h1,w1)(h-1, w-1) is the bottom-right cell. You are given a map that lists the height of every cell, together with the starting cell of your trip.

The difficulty of a route is the total energy spent on it. From one cell you can move to an adjacent cell in any of the eight directions: up, left, down, right and the four diagonals. You cannot leave the map, and you cannot enter a dangerous cell.

Moving to a cell of the same height spends 1 unit of energy. Moving to a cell that is dd units higher or lower spends (d+1)2(d+1)^2 units of energy.

You and your friend want to reach the highest cell in the grid. There is exactly one highest cell. Find the difficulty of the easiest route, the route that spends the least energy.

Input

The first line contains the number of test cases TT. (1T201 \le T \le 20)

Each test case is given in the following format.

  • The first line contains the height hh and the width ww of the grid. (3h1003 \le h \le 100, 3w1003 \le w \le 100)
  • The next hh lines describe the map. Each line is a string of ww characters. Each character is a digit from 0 to 9 giving the height of that cell, or # marking a dangerous cell. The digit 9 is the highest.
  • The last line contains the starting position xx and yy. (0xh10 \le x \le h-1, 0yw10 \le y \le w-1) The starting cell is not a dangerous cell.

Output

For each test case, print the energy needed for the easiest route on its own line. If there is no route from the starting position to the highest cell, print NO.

Hint

In the first example the easiest route is (0, 0) -> (1, 0) -> (2, 1) -> (2, 2) -> (2, 3). The energy spent on the four moves is 1, 4, 4 and 4.