You are given an R x C 2D grid consisting of several light panels. Each cell contains either a *
or a .
. *
means the panel is on, and .
means it's off.
If you touch a panel, its state will be toggled. That means, if you touch a panel that's on, it will turn off, and if you touch a panel that's off, it will turn on. But if we touch a panel, all its horizontal, vertical, and diagonal adjacent panels will also toggle their states.
Now you are given the configuration of the grid. Your goal is to turn on all the lights. Print the minimum number of touches required to achieve this goal.
Input
Input starts with an integer T (≤ 125), denoting the number of test cases.
Each test case starts with two integers R (1 ≤ R ≤ 8) and C (1 ≤ C ≤ 8). Then there will be R lines each containing C characters (*
or .
).
Output
For each test case, print the case number and the minimum number of touches required to have all the light panels in the board on at the same time. If it is not possible then print impossible
.
Sample
Sample Input | Sample Output |
---|---|
4 5 5 ***** *...* *...* *...* ***** 1 2 .* 3 3 **. **. ... 4 4 *... **.. ..** ...* | Case 1: 1 Case 2: impossible Case 3: 2 Case 4: 10 |