h,w = list(map(int,input().split()))

s0 = "."*(w+2)

S = [s0]



for i in range(h):

    S.append("."+eval(input())+".")

    

S.append(s0)



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

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

        if S[i][j] == ".":

            num = 0

            for k in range(3):

                if S[i-1][j-1+k] == "#":

                    num += 1

            if S[i][j-1] == "#":

                num += 1

            if S[i][j+1] == "#":

                num += 1

            for k in range(3):

                if S[i+1][j-1+k] == "#":

                    num += 1

            S[i] = list(S[i])

            S[i][j] = str(num)

            S[i] = "".join(S[i])

            

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

    print((S[i][1:w+1]))
h,w = map(int,input().split())

masume = [list(["."] for _ in range(w+2))]



for i in range(h):

    masume.append(list(["."]+list(input())+["."]))

    

masume.append(list(["."] for _ in range(w+2)))



dx = [-1,0,1,-1,1,-1,0,1]

dy = [1,1,1,0,0,-1,-1,-1]



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

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

        count_mine = 0

        

        if masume[i][j] == ".":

            for k in range(8):

                if masume[i+dy[k]][j+dx[k]] == "#":

                    count_mine += 1



            masume[i][j] = str(count_mine)

            

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

    print(*masume[i][1:-1],sep="")

h, w = list(map(int, input().split()))
s0 = "." * (w + 2)
S = [s0]
for i in range(h):
    S.append("." + eval(input()) + ".")
S.append(s0)
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if S[i][j] == ".":
            num = 0
            for k in range(3):
                if S[i - 1][j - 1 + k] == "#":
                    num += 1
            if S[i][j - 1] == "#":
                num += 1
            if S[i][j + 1] == "#":
                num += 1
            for k in range(3):
                if S[i + 1][j - 1 + k] == "#":
                    num += 1
            S[i] = list(S[i])
            S[i][j] = str(num)
            S[i] = "".join(S[i])
for i in range(1, h + 1):
    print((S[i][1 : w + 1]))

h, w = map(int, input().split())
masume = [list(["."] for _ in range(w + 2))]
for i in range(h):
    masume.append(list(["."] + list(input()) + ["."]))
masume.append(list(["."] for _ in range(w + 2)))
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [1, 1, 1, 0, 0, -1, -1, -1]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        count_mine = 0
        if masume[i][j] == ".":
            for k in range(8):
                if masume[i + dy[k]][j + dx[k]] == "#":
                    count_mine += 1
            masume[i][j] = str(count_mine)
for i in range(1, h + 1):
    print(*masume[i][1:-1], sep="")

-h, w = list(map(int, input().split())) -s0 = "." * (w + 2) -S = [s0] +h, w = map(int, input().split()) +masume = [list(["."] for _ in range(w + 2))] -    S.append("." + eval(input()) + ".") -S.append(s0) +    masume.append(list(["."] + list(input()) + ["."])) +masume.append(list(["."] for _ in range(w + 2))) +dx = [-1, 0, 1, -1, 1, -1, 0, 1] +dy = [1, 1, 1, 0, 0, -1, -1, -1] -        if S[i][j] == ".": -            num = 0 -            for k in range(3): -                if S[i - 1][j - 1 + k] == "#": -                    num += 1 -            if S[i][j - 1] == "#": -                num += 1 -            if S[i][j + 1] == "#": -                num += 1 -            for k in range(3): -                if S[i + 1][j - 1 + k] == "#": -                    num += 1 -            S[i] = list(S[i]) -            S[i][j] = str(num) -            S[i] = "".join(S[i]) +        count_mine = 0 +        if masume[i][j] == ".": +            for k in range(8): +                if masume[i + dy[k]][j + dx[k]] == "#": +                    count_mine += 1 +            masume[i][j] = str(count_mine) -    print((S[i][1 : w + 1])) +    print(*masume[i][1:-1], sep="")