Shirogane and Shinomiya are walking home together. They want to spend as long as possible walking from their school at to their home at .
The area is represented by an grid. Cell is in the -th row from the top and the -th column from the left. A . represents a passable cell, and a # represents a wall.
They must follow all of these rules:
The last rule means that, after a horizontal move followed immediately by one downward move, they cannot immediately move horizontally in the opposite direction. For example, right, down, left is forbidden, while right, down, down, left is allowed, provided that the other rules are also satisfied.
Each move to an adjacent cell has distance . Find the distance of the longest valid path from to . If no such path exists, output .
The input is given in the following format.
For each test case, output the distance of the longest valid path on a separate line. If the destination is unreachable, output . Output the answers in the order the test cases appear in the input.
In the first test case, they can reach home by moving one cell right and then one cell down. The longest valid path has distance .
In the second test case, they cannot move from the starting cell, so home is unreachable.
In the third test case, they can move four cells right, two cells down, four cells left, two cells down, and four cells right. This path obeys all the rules and has distance . No longer valid path exists.
The first line contains the number of test cases . Each test case is given in the following format.
The first line of each test case contains the grid size . The -th of the following lines contains a string of length , representing the -th row of the grid.
. or # ()...