Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2194.   Mine
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 1852   Accepted Runs: 678

You must be very familiar with the game "Minesweeper". It is played on an N*N grid, and there are M mines hided in the grid. Your task is to mark the mines' positions without touching them.

If a position containing a mine is touched, you lose the game. If a position not containing a mine is touched, an integer K (0 ≤ K ≤ 8) appears indicating that there are K mines in the eight adjacent positions. If K = 0, the eight adjacent positions will be touched automatically, new numbers will appear and this process is repeated until no new number is 0.

Given the distribution of the mines, output the numbers appearing after the player's first touch.

Input

The first line of each case is two numbers N (1 ≤ N ≤ 100) and M (0 ≤ M ≤ N*N), indicating the size of the grid and the number of mines. Each of the following M lines contains two numbers Xi and Yi (1 ≤ Xi,Yi ≤ N) indicating there is a mine in the Xi-th row and Yi-th colomn. You can assume there is at most one mine in one position. The last line of each case is two numbers X and Y, indicating the position of the player's first touch.

The input is terminated by a test case starting with N = M = 0. This test case should not be processed.

Output

If the player touches the mine, just output "oops!".

If the player doesn't touch the mine, output the numbers appearing after the touch. If a position is touched by the player or by the computer automatically, output the number. If a position is not touched, output a dot '.'.

Output a blank line after each test case.

Sample Input

9 10
1 5
1 7
2 3
2 5
4 8
5 2
7 7
7 9
8 6
9 2
1 5

9 10
1 5
1 7
2 3
2 5
4 8
5 2
7 7
7 9
8 6
9 2
5 5

0 0


Sample Output

oops!

.........
.........
..12111..
..10001..
..10001..
1110011..
000012...
11101....
..101....


Author: Roba

Source: TOJ 2006 Weekly Contest 4
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:G.D.Retop. Developer: SuperHacker, G.D.Retop