Minesweeper

Time limit1sMemory limit128 MB

Problem

Minesweeper is played on an $n \times n$ grid. $m$ mines are hidden, one per cell, on distinct cells.

The player repeatedly picks a cell and opens it.

  • If the player opens a cell that contains a mine, the player loses.
  • If the player opens a cell with no mine, that cell shows a number between 0 and 8: the count of mines among the 8 cells adjacent to it horizontally, vertically, or diagonally.

The player wins by opening every safe cell until only the $m$ mined cells remain unopened. Those remaining $m$ cells must all be mines.

Your task is to read the state of a partially played game and print the corresponding current state of the grid.

Input

The first line contains a positive integer $n$, the size of the grid ($1 \le n \le 10$).

The next $n$ lines describe the mine layout. Each line represents one row using $n$ characters: a period (.) is a cell with no mine, and an asterisk (*) is a cell with a mine.

The following $n$ lines each contain a string of length $n$ describing which cells have been opened. A lowercase x marks an already-opened cell, and a period (.) marks a cell that has not been opened.

Output

Print the current state of the grid on $n$ lines.

  • For each opened cell that contains no mine, print the number of adjacent mines (between 0 and 8).
  • If at least one mined cell has been opened, print every mined cell as an asterisk (*).
  • Print every other cell as a period (.).