Input Format: M N H I X
Input Format: M N H I X
Given a field divided into m rows, n columns, each cell containing h (denoting a healthy plant), i (denoting a
infected plant) or x (denoting empty spot), find the number of days required to turn all healthy plants to infected. In
one day, a infected plant can make infect neighboring healthy plants. A cell can have at most 4 neighbors (left, right,
front and back).
Input Format
The first line contains and integer t denoting the number of test cases. The second line consists of two space
separated integers m and n . The next m rows each contain n characters.
Output Format
For each test case output the number of days required. If it’s not possible to turn all healthy plants to infected,
output -1 . If there are no healthy plants output 0 .
Sample Input
9
2 3
ixh
hhh
1 2
ix
3 3
hhh
hih
hhh
1 3
hxi
2 1
h
x
3 3
ihh
hhh
hhh
1 9
hixhihhhx
3 1
h
i
h
1 1
x
Sample Output
4
0
2
-1
-1
4
3
1
0
Explanation
For the case
ixh
hhh
After Day 1
ixh
ihh
After Day 2
ixh
iih
After Day 3
ixh
iii
After Day 4
ixi
iii
Constraints
1 <= t <= 1000
1 <= m,n <= 100