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

S = [[s if s == '#' else 0 for s in input().rstrip()] for _ in range(H)]



for i in range(H):

    for j in range(W):

        count = 0

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

            if i-1 >= 0:

                if S[i-1][j] == '#':  # top

                    count += 1

                if j-1 >= 0 and S[i-1][j-1] == '#':  # top_left

                    count += 1

                if j+1 < W and S[i-1][j+1] == '#':  # top_right

                    count += 1

            if j-1 >= 0 and S[i][j-1] == '#':  # mid_left

                count += 1

            if j+1 < W and S[i][j+1] == '#':  # mid_right

                count += 1

            if i+1 < H:

                if S[i+1][j] == '#':  # bottom_center

                    count += 1

                if j-1 >= 0 and S[i+1][j-1] == '#':  # bottom_left

                    count += 1

                if j+1 < W and S[i+1][j+1] == '#':  # bottom_right

                    count += 1

            S[i][j] += count



for row in S:

    for s in row:

        print(s, end="")

    print()

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

S = [[s if s == '#' else 0 for s in input().rstrip()] for _ in range(H)]



for i in S:

    i.insert(0, 0)

    i.append(0)



zero_ls = [i for i in range(W+2)]

S.insert(0, zero_ls)

S.append(zero_ls)



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

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

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

            if S[i-1][j] != '#':  # top_center

                S[i-1][j] += 1

            if S[i-1][j-1] != '#':  # top_left

                S[i-1][j-1] += 1

            if S[i-1][j+1] != '#':  # top_right

                S[i-1][j+1] += 1

            if S[i][j-1] != '#':  # mid_left

                S[i][j-1] += 1

            if S[i][j+1] != '#':  # mid_right

                S[i][j+1] += 1

            if S[i+1][j] != '#':  # bottom_center

                S[i+1][j] += 1

            if S[i+1][j-1] != '#':  # bottom_left

                S[i+1][j-1] += 1

            if S[i+1][j+1] != '#':  # bottom_right

                S[i+1][j+1] += 1



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

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

        print(S[i][j], end="")

    print()

H, W = map(int, input().split())
S = [[s if s == "#" else 0 for s in input().rstrip()] for _ in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        if S[i][j] != "#":
            if i - 1 >= 0:
                if S[i - 1][j] == "#":  # top
                    count += 1
                if j - 1 >= 0 and S[i - 1][j - 1] == "#":  # top_left
                    count += 1
                if j + 1 < W and S[i - 1][j + 1] == "#":  # top_right
                    count += 1
            if j - 1 >= 0 and S[i][j - 1] == "#":  # mid_left
                count += 1
            if j + 1 < W and S[i][j + 1] == "#":  # mid_right
                count += 1
            if i + 1 < H:
                if S[i + 1][j] == "#":  # bottom_center
                    count += 1
                if j - 1 >= 0 and S[i + 1][j - 1] == "#":  # bottom_left
                    count += 1
                if j + 1 < W and S[i + 1][j + 1] == "#":  # bottom_right
                    count += 1
            S[i][j] += count
for row in S:
    for s in row:
        print(s, end="")
    print()

H, W = map(int, input().split())
S = [[s if s == "#" else 0 for s in input().rstrip()] for _ in range(H)]
for i in S:
    i.insert(0, 0)
    i.append(0)
zero_ls = [i for i in range(W + 2)]
S.insert(0, zero_ls)
S.append(zero_ls)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            if S[i - 1][j] != "#":  # top_center
                S[i - 1][j] += 1
            if S[i - 1][j - 1] != "#":  # top_left
                S[i - 1][j - 1] += 1
            if S[i - 1][j + 1] != "#":  # top_right
                S[i - 1][j + 1] += 1
            if S[i][j - 1] != "#":  # mid_left
                S[i][j - 1] += 1
            if S[i][j + 1] != "#":  # mid_right
                S[i][j + 1] += 1
            if S[i + 1][j] != "#":  # bottom_center
                S[i + 1][j] += 1
            if S[i + 1][j - 1] != "#":  # bottom_left
                S[i + 1][j - 1] += 1
            if S[i + 1][j + 1] != "#":  # bottom_right
                S[i + 1][j + 1] += 1
for i in range(1, H + 1):
    for j in range(1, W + 1):
        print(S[i][j], end="")
    print()

-for i in range(H): -    for j in range(W): -        count = 0 -        if S[i][j] != "#": -            if i - 1 >= 0: -                if S[i - 1][j] == "#":  # top -                    count += 1 -                if j - 1 >= 0 and S[i - 1][j - 1] == "#":  # top_left -                    count += 1 -                if j + 1 < W and S[i - 1][j + 1] == "#":  # top_right -                    count += 1 -            if j - 1 >= 0 and S[i][j - 1] == "#":  # mid_left -                count += 1 -            if j + 1 < W and S[i][j + 1] == "#":  # mid_right -                count += 1 -            if i + 1 < H: -                if S[i + 1][j] == "#":  # bottom_center -                    count += 1 -                if j - 1 >= 0 and S[i + 1][j - 1] == "#":  # bottom_left -                    count += 1 -                if j + 1 < W and S[i + 1][j + 1] == "#":  # bottom_right -                    count += 1 -            S[i][j] += count -for row in S: -    for s in row: -        print(s, end="") +for i in S: +    i.insert(0, 0) +    i.append(0) +zero_ls = [i for i in range(W + 2)] +S.insert(0, zero_ls) +S.append(zero_ls) +for i in range(1, H + 1): +    for j in range(1, W + 1): +        if S[i][j] == "#": +            if S[i - 1][j] != "#":  # top_center +                S[i - 1][j] += 1 +            if S[i - 1][j - 1] != "#":  # top_left +                S[i - 1][j - 1] += 1 +            if S[i - 1][j + 1] != "#":  # top_right +                S[i - 1][j + 1] += 1 +            if S[i][j - 1] != "#":  # mid_left +                S[i][j - 1] += 1 +            if S[i][j + 1] != "#":  # mid_right +                S[i][j + 1] += 1 +            if S[i + 1][j] != "#":  # bottom_center +                S[i + 1][j] += 1 +            if S[i + 1][j - 1] != "#":  # bottom_left +                S[i + 1][j - 1] += 1 +            if S[i + 1][j + 1] != "#":  # bottom_right +                S[i + 1][j + 1] += 1 +for i in range(1, H + 1): +    for j in range(1, W + 1): +        print(S[i][j], end="")