You are given a maze. It is a grid with rows and
columns. Rows and columns are both numbered from
to
. The intersection of the
-th row and
-th column is denoted by
. Some cells of the maze are obstacles.
Initially, you are standing in the top left corner . Your goal is to reach the bottom right corner
.
You can move in four directions from : up to
, down to
, left to
or right to
.
You cannot move in the same direction for more than consecutive moves, you cannot leave the grid and the cells with obstacle are unreachable. What is the minimum number of moves to reach
?
The input consists of multiple test cases.
The first line contains a single integer
![]()
- the number of the test cases, the description of the test cases follows.
The first line contains two integers
![]()
, denoting the size of the maze and the most consecutive moves you can perform in one direction.
The next
lines describe the maze. Each of them contains a string of length
that consists only of symbols . and *. The
-th character of the
-th line corresponds to the cell of the maze at row
and column
. Symbol . denotes a free cell, while symbol * denotes a cell with an obstacle.
Ensure that the number of test cases with
will not exceed
.
For each test case, print a single integer:
if it is impossible to reach
, otherwise the minimum number of moves.