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

S = []

for _ in range(H):

    S.append(list(eval(input())))



d = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]

for i in range(H):

    for j in range(W):

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

            cnt = 0

            for r in range(8):

                y = i + d[r][0]

                x = j + d[r][1]

                if 0 <= x < W and 0 <= y < H and S[y][x] == '#':

                        cnt = cnt + 1

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



for i in range(H):

    print((''.join(S[i])))

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

S=[[0 for i in range(W)] for j in range(H)]

for i in range(H):

  a=list(map(str,eval(input())))

  for j in range(W):

    S[i][j]=a[j]

  a=[]

#print(S)

V=[[0 for i in range(W)] for j in range(H)]

for m in range(H):

  for n in range(W):

    if S[m][n]=="#":

      V[m][n]="#"

      continue

      

    if m > 0 and n > 0 and S[m-1][n-1]=="#":

      V[m][n] += 1

    if m > 0 and S[m-1][n]=="#":

      V[m][n] += 1

    if m > 0 and n < W - 1 and S[m-1][n+1]=="#":

      V[m][n] += 1

    if n > 0 and S[m][n-1]=="#":

      V[m][n] += 1

    if n < W - 1 and S[m][n+1]=="#":

      V[m][n] += 1

    if m < H - 1 and n > 0 and S[m+1][n-1]=="#":

      V[m][n] += 1

    if m < H - 1 and S[m+1][n]=="#":

      V[m][n] += 1

    if m < H - 1 and n < W - 1 and S[m+1][n+1]=="#":

      V[m][n] += 1



a=[]

#print(V)

for k in range(H):

  for l in range(W):

    a.append(V[k][l])

  print(("".join(map(str,a))))

  a=[]
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
    S.append(list(eval(input())))
d = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for r in range(8):
                y = i + d[r][0]
                x = j + d[r][1]
                if 0 <= x < W and 0 <= y < H and S[y][x] == "#":
                    cnt = cnt + 1
            S[i][j] = str(cnt)
for i in range(H):
    print(("".join(S[i])))

H, W = list(map(int, input().split()))
S = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    a = list(map(str, eval(input())))
    for j in range(W):
        S[i][j] = a[j]
    a = []
# print(S)
V = [[0 for i in range(W)] for j in range(H)]
for m in range(H):
    for n in range(W):
        if S[m][n] == "#":
            V[m][n] = "#"
            continue
        if m > 0 and n > 0 and S[m - 1][n - 1] == "#":
            V[m][n] += 1
        if m > 0 and S[m - 1][n] == "#":
            V[m][n] += 1
        if m > 0 and n < W - 1 and S[m - 1][n + 1] == "#":
            V[m][n] += 1
        if n > 0 and S[m][n - 1] == "#":
            V[m][n] += 1
        if n < W - 1 and S[m][n + 1] == "#":
            V[m][n] += 1
        if m < H - 1 and n > 0 and S[m + 1][n - 1] == "#":
            V[m][n] += 1
        if m < H - 1 and S[m + 1][n] == "#":
            V[m][n] += 1
        if m < H - 1 and n < W - 1 and S[m + 1][n + 1] == "#":
            V[m][n] += 1
a = []
# print(V)
for k in range(H):
    for l in range(W):
        a.append(V[k][l])
    print(("".join(map(str, a))))
    a = []

-S = [] -for _ in range(H): -    S.append(list(eval(input()))) -d = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] +S = [[0 for i in range(W)] for j in range(H)] +    a = list(map(str, eval(input()))) -        if S[i][j] == ".": -            cnt = 0 -            for r in range(8): -                y = i + d[r][0] -                x = j + d[r][1] -                if 0 <= x < W and 0 <= y < H and S[y][x] == "#": -                    cnt = cnt + 1 -            S[i][j] = str(cnt) -for i in range(H): -    print(("".join(S[i]))) +        S[i][j] = a[j] +    a = [] +# print(S) +V = [[0 for i in range(W)] for j in range(H)] +for m in range(H): +    for n in range(W): +        if S[m][n] == "#": +            V[m][n] = "#" +            continue +        if m > 0 and n > 0 and S[m - 1][n - 1] == "#": +            V[m][n] += 1 +        if m > 0 and S[m - 1][n] == "#": +            V[m][n] += 1 +        if m > 0 and n < W - 1 and S[m - 1][n + 1] == "#": +            V[m][n] += 1 +        if n > 0 and S[m][n - 1] == "#": +            V[m][n] += 1 +        if n < W - 1 and S[m][n + 1] == "#": +            V[m][n] += 1 +        if m < H - 1 and n > 0 and S[m + 1][n - 1] == "#": +            V[m][n] += 1 +        if m < H - 1 and S[m + 1][n] == "#": +            V[m][n] += 1 +        if m < H - 1 and n < W - 1 and S[m + 1][n + 1] == "#": +            V[m][n] += 1 +a = [] +# print(V) +for k in range(H): +    for l in range(W): +        a.append(V[k][l]) +    print(("".join(map(str, a)))) +    a = []