You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.


import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())
S = [readline().decode('utf8').rstrip() for _ in range(H)]

ans = [[0 if cell == '.' else '#' for cell in row] for row in S]
print(ans)

for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            continue
        for dx, dy in itertools.product([-1, 0, 1], repeat=2):
            x = i + dx
            y = j + dy
            if x < 0 or x >= H:
                continue
            if y < 0 or y >= W:
                continue
            if S[x][y] == '#':
                continue

            ans[x][y] += 1

for row in ans:
    print(*row, sep=' ')



import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())
S = [readline().decode('utf8').rstrip() for _ in range(H)]

ans = [[0 if cell == '.' else '#' for cell in row] for row in S]
# print(ans)

for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            continue
        for dx, dy in itertools.product([-1, 0, 1], repeat=2):
            x = i + dx
            y = j + dy
            if x < 0 or x >= H:
                continue
            if y < 0 or y >= W:
                continue
            if S[x][y] == '#':
                continue

            ans[x][y] += 1

for row in ans:
    print(*row,sep='')
