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

L = []

blank = ['.' for _ in range(W+2)]

L.append(blank)



def cnt(x):

    if x == '#':

        return 1

    else:

        return 0



for _ in range(H):

    L.append(['.']+list(input())+['.'])

L.append(blank)



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

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

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

            print('#',end='')

        else:

            c = 0

            for x in [-1,0,1]:

                for y in [-1,0,1]:

                    if not (x==y==0):

                        c += cnt(L[i+x][j+y])

            print(c,end='')

    print()

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

L = []



def cange(x):

  if x == '.':

    return 0

  else:

    return 1



zerofill = [ '.' for _ in range(W+2)] 



L.append(zerofill)

for _ in range(H):

  L.append(['.']+list(input())+['.'])

L.append(zerofill)



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

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

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

      cnt = 0

      for x in [-1,0,1]:

        for y in [-1,0,1]:

          if not (x == 0 and y == 0):

            cnt += cange(L[i+x][j+y])

      print(cnt,end='')

    else:

      print('#',end='')

  print()

H, W = map(int, input().split())
L = []
blank = ["." for _ in range(W + 2)]
L.append(blank)


def cnt(x):
    if x == "#":
        return 1
    else:
        return 0


for _ in range(H):
    L.append(["."] + list(input()) + ["."])
L.append(blank)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if L[i][j] == "#":
            print("#", end="")
        else:
            c = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if not (x == y == 0):
                        c += cnt(L[i + x][j + y])
            print(c, end="")
    print()

H, W = map(int, input().split())
L = []


def cange(x):
    if x == ".":
        return 0
    else:
        return 1


zerofill = ["." for _ in range(W + 2)]
L.append(zerofill)
for _ in range(H):
    L.append(["."] + list(input()) + ["."])
L.append(zerofill)
for i in range(1, H + 1):
    for j in range(1, 1 + W):
        if L[i][j] == ".":
            cnt = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if not (x == 0 and y == 0):
                        cnt += cange(L[i + x][j + y])
            print(cnt, end="")
        else:
            print("#", end="")
    print()

-blank = ["." for _ in range(W + 2)] -L.append(blank) -def cnt(x): -    if x == "#": +def cange(x): +    if x == ".": +        return 0 +    else: -    else: -        return 0 +zerofill = ["." for _ in range(W + 2)] +L.append(zerofill) -L.append(blank) +L.append(zerofill) -    for j in range(1, W + 1): -        if L[i][j] == "#": -            print("#", end="") -        else: -            c = 0 +    for j in range(1, 1 + W): +        if L[i][j] == ".": +            cnt = 0 -                    if not (x == y == 0): -                        c += cnt(L[i + x][j + y]) -            print(c, end="") +                    if not (x == 0 and y == 0): +                        cnt += cange(L[i + x][j + y]) +            print(cnt, end="") +        else: +            print("#", end="")