Under construction

Still being built. Things may change

Mine Map

Time limit1sMemory limit128 MB

Summary
Mark each cell of a grid as mine, safely entered, risky, or unreachable, following a detector-driven walk from the center.
Level

Medium4 of 10

Topics
BFS, Simulation, Implementation
Solved
No attempts yet

Problem

An organization has built a giant maze-like vault to store an important problemset. The vault is a square grid of rooms whose side length is odd; each room is identified by its (row, column) coordinates, and adjacent rooms are connected by doors.

To make intrusion harder, mines are placed in some of the rooms. Fortunately, an intruder carries a mine detector. The detector can be used from any room and reports only whether at least one of the up to eight rooms adjacent to the current room contains a mine — never how many, and never in which direction.

The intruder starts in the center room, which is guaranteed to contain no mine, and follows this simple strategy:

  • If the detector reports no adjacent mine in the current room, all eight surrounding rooms can be searched (entered) safely. Mark such a room with ..
  • If the detector reports one or more adjacent mines, the intruder does not risk advancing any farther from that room (a retreat). Mark such a room with #. Such a room may still be reached later through another safe route, so it counts as reached and remains marked #.

In other words, mark every room reachable from the center under this rule with . or #. Mark every room that contains a mine with *, and mark every room that can never be reached with ?.

For each vault blueprint, output this map.

Input

The first line contains the number of scenarios.

Each scenario begins with a line containing the odd integer nn (1<n<3001 < n < 300), the side length of the vault. The next line contains the number of mines mm (mm is at least 1 and does not exceed the number of rooms). Then follow mm lines, each containing two integers rr and cc (1≤r,c≤n1 \le r, c \le n), the row and column of a mine.

Output

For each scenario, first print Scenario #i:, where ii is the scenario number starting at 1. Then print the vault map described above on nn lines. Print a blank line between two consecutive scenarios.

Examples1

  1. Example 1

    Input
    3
    3
    1
    1 2
    5
    4
    3 1
    1 3
    3 5
    5 3
    5
    2
    1 1
    5 3
    
    Expected output
    Scenario #1:
    ?*?
    ?#?
    ???
    
    Scenario #2:
    ??*??
    ?###?
    *#.#*
    ?###?
    ??*??
    
    Scenario #3:
    *#...
    ##...
    .....
    .###.
    .#*#.