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

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

[S.append("."+eval(input())+".") for _ in range(H)]

S.append("."*(W+2))

ans = []



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

    ans_tmp = ""

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

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

            tmp = 0

            for i in [-1,0,1]:

                for j in [-1,0,1]:

                    if S[h+i][w+j] == "#":

                        tmp += 1

            ans_tmp += str(tmp)

        else:

            ans_tmp += "#"

    ans.append(ans_tmp)

for s in ans:

    print(s)

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

S = [input() for _ in range(H)]



Ans = [[S[h][w] for w in range(W)] for h in range(H)]



for h in range(H):

    for w in range(W):

        if Ans[h][w] == '.':

            x = 0

            for i in [-1, 0, 1]:

                for j in [-1, 0, 1]:

                    if 0 <= h + i and h + i < H and 0 <= w + j and w + j < W and S[h + i][w + j] == '#':

                        x += 1

            Ans[h][w] = x



for h in range(H):

    for w in range(W):

        print(Ans[h][w], end="")

    print("")

H, W = list(map(int, input().split()))
S = ["." * (W + 2)]
[S.append("." + eval(input()) + ".") for _ in range(H)]
S.append("." * (W + 2))
ans = []
for h in range(1, H + 1):
    ans_tmp = ""
    for w in range(1, W + 1):
        if S[h][w] == ".":
            tmp = 0
            for i in [-1, 0, 1]:
                for j in [-1, 0, 1]:
                    if S[h + i][w + j] == "#":
                        tmp += 1
            ans_tmp += str(tmp)
        else:
            ans_tmp += "#"
    ans.append(ans_tmp)
for s in ans:
    print(s)

H, W = map(int, input().split())
S = [input() for _ in range(H)]
Ans = [[S[h][w] for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if Ans[h][w] == ".":
            x = 0
            for i in [-1, 0, 1]:
                for j in [-1, 0, 1]:
                    if (
                        0 <= h + i
                        and h + i < H
                        and 0 <= w + j
                        and w + j < W
                        and S[h + i][w + j] == "#"
                    ):
                        x += 1
            Ans[h][w] = x
for h in range(H):
    for w in range(W):
        print(Ans[h][w], end="")
    print("")

-H, W = list(map(int, input().split())) -S = ["." * (W + 2)] -[S.append("." + eval(input()) + ".") for _ in range(H)] -S.append("." * (W + 2)) -ans = [] -for h in range(1, H + 1): -    ans_tmp = "" -    for w in range(1, W + 1): -        if S[h][w] == ".": -            tmp = 0 +H, W = map(int, input().split()) +S = [input() for _ in range(H)] +Ans = [[S[h][w] for w in range(W)] for h in range(H)] +for h in range(H): +    for w in range(W): +        if Ans[h][w] == ".": +            x = 0 -                    if S[h + i][w + j] == "#": -                        tmp += 1 -            ans_tmp += str(tmp) -        else: -            ans_tmp += "#" -    ans.append(ans_tmp) -for s in ans: -    print(s) +                    if ( +                        0 <= h + i +                        and h + i < H +                        and 0 <= w + j +                        and w + j < W +                        and S[h + i][w + j] == "#" +                    ): +                        x += 1 +            Ans[h][w] = x +for h in range(H): +    for w in range(W): +        print(Ans[h][w], end="") +    print("")