Problem E: Mine Sweeper #2

Problem E: Mine Sweeper #2

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
[Submit] [Status] [Web Board] [Creator:]

Description

Akter wants to develop a ‘Minesweeper’ game like the one below. To do this, let’s first write a program that counts how many mines are placed among the cells adjacent to a cell without mines and outputs that value.


Write a program that, given a minefield, checks the number of mines among neighboring cells (horizontally, vertically, and diagonally adjacent) for cells without mines and outputs that number, and for cells containing mines, outputs the mine shape as is.

Input

First, the number of test cases T (1 <= T <= 10) is input.
Next, M and N (3 <= M, N <= 30), representing a minefield of size M x N (M: height, N: width), are input.
Then, the M x N minefield is input.
Cells without mines are marked with ‘.’, and cells containing mines are marked with ‘*’.

Output

For each test case, output the number of mines in the surrounding cells in an M x N size. Print '*' for the locations where mines are present as usual. Do not print blank lines between the results.

Sample Input Copy

2
3 4
....
.*..
....
5 5
*....
....*
.*.*.
.*...
.....

Sample Output Copy

1110
1*10
1110
*1011
2222*
2*3*2
2*311
11100