Sapper
On the weekend, you decided to create your first computer game and chose to start with something simple: "Minesweeper."
"Minesweeper" is a single-player game set on a grid of N×M cells. Mines are hidden in K of these cells. In the other cells, a number from 1 to 8 may be displayed, indicating the number of mines in the adjacent cells. If there are no mines nearby, the cell remains blank. Cells are considered adjacent if they share at least one point. Each cell can contain at most one mine.
You've already developed a module to place mines on the game board. Your next task is to generate the game map according to these rules.
Input
The first line contains three integers N, M, K (1 ≤ N ≤ 50, 1 ≤ M ≤ 50, 0 ≤ K ≤ N·M). The next K lines each contain two integers that specify the coordinates of the mines. The first integer indicates the row number, and the second indicates the column number. The top-left cell is at coordinates (1, 1), and the bottom-right cell is at coordinates (N, M).
Output
You must output a matrix with N rows and M columns representing the "Minesweeper" map.
The j-th character of the i-th row should be "*" if there is a mine in cell (i, j), a digit from 1 to 8 if there is a corresponding number in this cell, or "." if the cell (i, j) is empty.