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

S = [eval(input()) for i in range(H)]



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

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



A = [[] for i in range(H)]

for i in range(H):

    for j in range(W):

        count = 0

        for k in range(8):

            ny = i + dy[k]

            nx = j + dx[k]

            if S[i][j]:

                if 0 <= ny < H and 0 <= nx < W:

                    if S[ny][nx] == "#":

                        count += 1

        A[i].append(str(count))



for i in range(H):

    for j in range(W):

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

           A[i][j] = "#"

for i in range(H):

    print(("".join(A[i])))
H,W = list(map(int,input().split()))

S = [list(eval(input())) for i in range(H)]

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

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

for j in range(H):

    for i in range(W):

        cnt = 0

        for k in range(8):

            if 0<=i+dx[k]<W and 0<=j+dy[k]<H:

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

                    cnt += 1

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

            continue

        else:

            S[j][i] = cnt





for i in range(H):

    for j in range(W):

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



for i in range(H):

    print(("".join(S[i])))
H, W = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
dx = [1, 1, 1, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, -1, 1, 0, -1]
A = [[] for i in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        for k in range(8):
            ny = i + dy[k]
            nx = j + dx[k]
            if S[i][j]:
                if 0 <= ny < H and 0 <= nx < W:
                    if S[ny][nx] == "#":
                        count += 1
        A[i].append(str(count))
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            A[i][j] = "#"
for i in range(H):
    print(("".join(A[i])))

H, W = list(map(int, input().split()))
S = [list(eval(input())) for i in range(H)]
dx = [1, 1, 1, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, -1, 1, 0, -1]
for j in range(H):
    for i in range(W):
        cnt = 0
        for k in range(8):
            if 0 <= i + dx[k] < W and 0 <= j + dy[k] < H:
                if S[j + dy[k]][i + dx[k]] == "#":
                    cnt += 1
        if S[j][i] == "#":
            continue
        else:
            S[j][i] = cnt
for i in range(H):
    for j in range(W):
        S[i][j] = str(S[i][j])
for i in range(H):
    print(("".join(S[i])))

-S = [eval(input()) for i in range(H)] +S = [list(eval(input())) for i in range(H)] -A = [[] for i in range(H)] +for j in range(H): +    for i in range(W): +        cnt = 0 +        for k in range(8): +            if 0 <= i + dx[k] < W and 0 <= j + dy[k] < H: +                if S[j + dy[k]][i + dx[k]] == "#": +                    cnt += 1 +        if S[j][i] == "#": +            continue +        else: +            S[j][i] = cnt -        count = 0 -        for k in range(8): -            ny = i + dy[k] -            nx = j + dx[k] -            if S[i][j]: -                if 0 <= ny < H and 0 <= nx < W: -                    if S[ny][nx] == "#": -                        count += 1 -        A[i].append(str(count)) +        S[i][j] = str(S[i][j]) -    for j in range(W): -        if S[i][j] == "#": -            A[i][j] = "#" -for i in range(H): -    print(("".join(A[i]))) +    print(("".join(S[i])))