H, W = map(int,input().split())

S = ["."*(W+2)]+ ["."+input()+"." for k in range(H)] + ["."*(W+2)]

ans = [[0 for k in range(W)] for l in range(H)]



for x in range(1,W+1):

    for y in range(1,H+1):

        if S[y][x] == "#":

            ans[y-1][x-1] = "#"

        else:

            c = 0

            for dx in range(-1,2):

                for dy in range(-1,2):

                    if S[y+dy][x+dx] == "#":

                        c += 1

            ans[y-1][x-1] = c



for e in ans:

    print(*e,sep="")

H, W = list(map(int,input().split()))

S = ["."+eval(input())+"." for k in range(H)]

S = ["."*(W+2)] + S + ["."*(W+2)]



A = [[""]*W for _ in range(H)]

for h in range(1,H+1):

    for w in range(1,W+1):

        if S[h][w] == "#":

            A[h-1][w-1] = "#"

        else:

            temp = 0

            for dx in range(-1,2):

                for dy in range(-1,2):

                    if S[h+dy][w+dx] == "#":

                        temp += 1

            A[h-1][w-1] = str(temp)

for e in A:

    print(("".join(e)))

H, W = map(int, input().split())
S = ["." * (W + 2)] + ["." + input() + "." for k in range(H)] + ["." * (W + 2)]
ans = [[0 for k in range(W)] for l in range(H)]
for x in range(1, W + 1):
    for y in range(1, H + 1):
        if S[y][x] == "#":
            ans[y - 1][x - 1] = "#"
        else:
            c = 0
            for dx in range(-1, 2):
                for dy in range(-1, 2):
                    if S[y + dy][x + dx] == "#":
                        c += 1
            ans[y - 1][x - 1] = c
for e in ans:
    print(*e, sep="")

H, W = list(map(int, input().split()))
S = ["." + eval(input()) + "." for k in range(H)]
S = ["." * (W + 2)] + S + ["." * (W + 2)]
A = [[""] * W for _ in range(H)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == "#":
            A[h - 1][w - 1] = "#"
        else:
            temp = 0
            for dx in range(-1, 2):
                for dy in range(-1, 2):
                    if S[h + dy][w + dx] == "#":
                        temp += 1
            A[h - 1][w - 1] = str(temp)
for e in A:
    print(("".join(e)))

-H, W = map(int, input().split()) -S = ["." * (W + 2)] + ["." + input() + "." for k in range(H)] + ["." * (W + 2)] -ans = [[0 for k in range(W)] for l in range(H)] -for x in range(1, W + 1): -    for y in range(1, H + 1): -        if S[y][x] == "#": -            ans[y - 1][x - 1] = "#" +H, W = list(map(int, input().split())) +S = ["." + eval(input()) + "." for k in range(H)] +S = ["." * (W + 2)] + S + ["." * (W + 2)] +A = [[""] * W for _ in range(H)] +for h in range(1, H + 1): +    for w in range(1, W + 1): +        if S[h][w] == "#": +            A[h - 1][w - 1] = "#" -            c = 0 +            temp = 0 -                    if S[y + dy][x + dx] == "#": -                        c += 1 -            ans[y - 1][x - 1] = c -for e in ans: -    print(*e, sep="") +                    if S[h + dy][w + dx] == "#": +                        temp += 1 +            A[h - 1][w - 1] = str(temp) +for e in A: +    print(("".join(e)))