Under construction

Still being built. Things may change

Minesweeper

Interview

Time limit4sMemory limit1024 MB

Summary
Given a solved Minesweeper board, check that every digit equals the number of flagged squares next to it.
Level

Easy2 of 10

Topics
Matrix, Implementation, Simulation
Solved
No attempts yet

Statement

Minesweeper is a single-player computer game. The objective of the game is to clear an abstract minefield without detonating a mine. When the game starts, the player is presented with a grid of n×mn \times m blank squares. If the player clicks a square without a mine, a digit is revealed in that square. The digit is the number of adjacent squares that contain mines. Two squares are adjacent if they share an edge or a corner, so a square can have at most 8 adjacent squares. Using logic, players can often deduce that certain other squares are mine-free or mine-filled. They then click more squares to clear them, or mark them with flag graphics to show a mine.

Clark Kent is a Minesweeper addict. With help from his Kryptonian powers, he solves them at lightning speed and gives them to you. Your job is to tell him whether the solved version is correct. A board is correctly solved if and only if every flagged square contains a mine, and every square containing a number X has exactly X adjacent flagged squares.

Input

The first line contains an integer T≤20T \le 20, the number of test cases.

Each test case is formatted as follows.

  • The first line contains two integers nn and mm separated by a single space, where 1≤n≤201 \le n \le 20 and 1≤m≤201 \le m \le 20.
  • The next nn lines contain mm characters each. Each character is a digit from 0 to 8 or 'F'. 'F' means Clark flagged the square. A digit is the number of mines in the adjacent squares.

Output

Output one line per test case.

  • Output 'Well done Clark!' if the board was solved successfully.
  • Output 'Please sweep the mine again!' otherwise.

Examples1

  1. Example 1

    Input
    2
    8 8
    F1012210
    1101FF21
    121234F1
    F2F11F21
    12111121
    1100012F
    F21101F2
    12F10111
    8 8
    F1012210
    1101FF21
    121234F1
    F2FF1F21
    12111121
    1100012F
    F21101F2
    12F10111
    
    Expected output
    Well done Clark!
    Please sweep the mine again!