Mine Map#2531

Mine Map

1 segundo
64 megabytes
Media (≈1350)

After the recent theft of the problemset for the ACM ICPC World Finals (by the notorious British super spy James B.—we reported on this some weeks ago), the ACM has decided to store all future problemsets in a high-security building. The security board responsible for creating this new vault proposed the brilliant idea to build it in the form of a giant maze. Essentially, this maze consists of many square rooms, arranged in the form of a square matrix, with all rooms connected to each other by a series of doors. Going through these rooms is the only way to reach the center where the problemsets are stored.

Obviously, traversing a maze where all rooms are connected to each other is not very difficult. Therefore, to make it more dangerous for potential intruders, some of the rooms are booby-trapped with mines. If someone enters the central room of the vault containing the problemsets, these mines are activated. Afterwards, opening a door leading to a room with a mine will trigger an alarm, and all security doors close immediately, trapping the intruder. This way, the ACM can determine who sent the spy and disqualify all teams from that nation.

Recently, however, the security board became aware of a new scanning device that can detect mines once they are activated. This detector can be used from within any of the vault's rooms and can tell the user whether any of the up to eight adjacent rooms contain a mine or not. Unfortunately, the board has already ordered a batch of these mines and now doesn't want to admit that this might have been a mistake. Instead, they simply want to distribute the mines in such a way that it is difficult to leave the center by just using the device. You are assigned to the team building the vault in order to help evaluate their designs.

A vault has the form of a quadrangle with sides of odd length. Each room in the vault can be described by a pair of coordinates, indicating the horizontal and vertical offsets relative to a fixed corner of the building. Each room has doors leading to neighboring rooms; more importantly, the mine detector can detect mines in all up to eight adjacent rooms. The device can only tell you whether there are any mines nearby, but not how many there are.

Your task is to create a special map from each of the vault design drafts. On the map, mark all rooms that can be safely reached by somebody starting from the center room (which is guaranteed not to contain a mine), using the new detector and the following simple strategy: When you are in a room where the detector reports no adjacent mines, search all surrounding rooms. Otherwise, do not risk triggering a mine and do not advance farther from this room (though you might later reach one of the surrounding rooms via another "safe" route).

Thus, if the intruder is in a room not adjacent to any mines, he will be able to go to all surrounding rooms—mark such a room with a ".". If the intruder enters a room that is adjacent to one or more mines, he will retreat—mark these rooms with a "#". To verify your work, the security board also wants you to mark the position of each mine with a "*". Finally, all remaining rooms should be marked with a "?".

Entrada

The first line contains the number of scenarios. Each scenario starts with a line containing the odd integer (1 < n < 300), indicating the length of one of the vault's outer walls. This is followed by the number of mines (which is positive and only limited by the number of rooms in the vault). Next come lines, each containing two integers and (1 \le r, c \le n), indicating the row and column of a mine.

Salida

The output for every scenario begins with a line containing "Scenario #i:", where is the number of the scenario, starting at . Then print an ASCII representation of the map of the vault as described above. Terminate the output for the scenario with a blank line.

Ejemplos

Ejemplo 1

Loading
Loading