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

S = []

for i in range(H):

    S.append(input())

A = []

for i in range(H + 2):

    A.append([0] * (W + 2))



for i in range(H):

    for j in range(W):

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

            for k in range(3):

                for l in range(3):

                    A[i + k][j + l] += 1



for i in range(H):

    for j in range(W):

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

            A[i + 1][j + 1] = '#'



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

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

        print(A[i][j], end='')

    print('')

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

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

B = []

B.append('.' * (W + 2))

for i in range(H):

    B.append('.' + S[i] + '.')

B.append('.' * (W + 2))

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

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

        if B[i][j] == '#':

            print('#', end='')

            continue

        c = 0

        if B[i - 1][j - 1] == '#':

            c += 1

        if B[i - 1][j + 1] == '#':

            c += 1

        if B[i + 1][j - 1] == '#':

            c += 1

        if B[i + 1][j + 1] == '#':

            c += 1

        if B[i][j - 1] == '#':

            c += 1

        if B[i][j + 1] == '#':

            c += 1

        if B[i + 1][j] == '#':

            c += 1

        if B[i - 1][j] == '#':

            c += 1

        print(c, end='')

    print('')

H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
A = []
for i in range(H + 2):
    A.append([0] * (W + 2))
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            for k in range(3):
                for l in range(3):
                    A[i + k][j + l] += 1
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            A[i + 1][j + 1] = "#"
for i in range(1, H + 1):
    for j in range(1, W + 1):
        print(A[i][j], end="")
    print("")

H, W = map(int, input().split())
S = [input() for i in range(H)]
B = []
B.append("." * (W + 2))
for i in range(H):
    B.append("." + S[i] + ".")
B.append("." * (W + 2))
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if B[i][j] == "#":
            print("#", end="")
            continue
        c = 0
        if B[i - 1][j - 1] == "#":
            c += 1
        if B[i - 1][j + 1] == "#":
            c += 1
        if B[i + 1][j - 1] == "#":
            c += 1
        if B[i + 1][j + 1] == "#":
            c += 1
        if B[i][j - 1] == "#":
            c += 1
        if B[i][j + 1] == "#":
            c += 1
        if B[i + 1][j] == "#":
            c += 1
        if B[i - 1][j] == "#":
            c += 1
        print(c, end="")
    print("")

-S = [] +S = [input() for i in range(H)] +B = [] +B.append("." * (W + 2)) -    S.append(input()) -A = [] -for i in range(H + 2): -    A.append([0] * (W + 2)) -for i in range(H): -    for j in range(W): -        if S[i][j] == "#": -            for k in range(3): -                for l in range(3): -                    A[i + k][j + l] += 1 -for i in range(H): -    for j in range(W): -        if S[i][j] == "#": -            A[i + 1][j + 1] = "#" +    B.append("." + S[i] + ".") +B.append("." * (W + 2)) -        print(A[i][j], end="") +        if B[i][j] == "#": +            print("#", end="") +            continue +        c = 0 +        if B[i - 1][j - 1] == "#": +            c += 1 +        if B[i - 1][j + 1] == "#": +            c += 1 +        if B[i + 1][j - 1] == "#": +            c += 1 +        if B[i + 1][j + 1] == "#": +            c += 1 +        if B[i][j - 1] == "#": +            c += 1 +        if B[i][j + 1] == "#": +            c += 1 +        if B[i + 1][j] == "#": +            c += 1 +        if B[i - 1][j] == "#": +            c += 1 +        print(c, end="")