|
Do you know Minesweeper, the famous video game? The player is initially presented with a grid of undifferentiated squares. Some randomly selected squares, unknown to the player, are designated to contain mines. One square can contain at most one mine.<br> |
|
<br> |
|
The game is played by revealing squares of the grid, typically by clicking them. After that, a digit is revealed in the square, indicating the number of adjacent squares (under 8-way connectivity, that is, if two squares share either an edge or a corner, they are considered adjacent) that contain mines. If this number is zero then the surrounding squares are automatically also revealed. This process applies recursively and automatically every time a new square with count zero is revealed.<br> |
|
<br> |
|
Now, given a Minesweeper situation, you need to check if it is possible that such a situation can occur after <strong>exactly</strong> 1 click on the grid. Note that the game is designed in such a way, that the first clicked square never contains a mine.<br> |
|
<br> |
|
<h2>Input:</h2> |
|
The first line contains a single integer <strong>T</strong>, <strong>T</strong> ≤ 20. <br> |
|
Then <strong>T</strong> test cases follow.<br> |
|
The first line of each test case contains two integers <strong>n</strong>, <strong>m</strong> which indicate the size of the grid (<strong>1 ≤ n ≤ 16, 1 ≤ m ≤ 32</strong>).<br> |
|
<strong>n</strong> lines follow, each line contains <strong>m</strong> characters describing the situation of the grid.<br> |
|
The meaning of the characters are as follows:<br> |
|
x: the square is not revealed after the first click<br> |
|
0 - 8: the number of mines that are adjacent to this square<br> |
|
<br> |
|
<h2>Output:</h2> |
|
Output a single line containing 'Yes' if the situation is valid after 1 click, and 'No' otherwise (quotes for clarity).<br> |
|
|