h,w=list(map(int,input().split()))

from collections import defaultdict

data=defaultdict(int)

for y in range(h):

    line=eval(input())

    for x in range(w):

        if line[x]=='#':

            data[(y,x)]=-1

            for i in range(-1,2):

                for j in range(-1,2):

                    if data[(y+i,x+j)]!=-1:

                        data[(y+i,x+j)]+=1

for y in range(h):

    s=''

    for x in range(w):

        if data[(y,x)]==-1:s+='#'

        else:s+=str(data[(y,x)])

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

Map=['.'*(W+2)]

for i in range(H):

    line='.'+eval(input())+'.'

    x=[]

    for j in range(W+2):

        x.append(line[j])

    Map.append(x)

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

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

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

        if Map[h][w]=='.':

            cnt=0

            for i,j in [(-1,-1),(-1,0),(0,-1),(1,-1),(-1,1),(1,0),(0,1),(1,1)]:

                if Map[h+i][w+j]=='#':cnt+=1

            Map[h][w]=str(cnt)

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

    print((''.join(Map[h][1:-1])))
h, w = list(map(int, input().split()))
from collections import defaultdict

data = defaultdict(int)
for y in range(h):
    line = eval(input())
    for x in range(w):
        if line[x] == "#":
            data[(y, x)] = -1
            for i in range(-1, 2):
                for j in range(-1, 2):
                    if data[(y + i, x + j)] != -1:
                        data[(y + i, x + j)] += 1
for y in range(h):
    s = ""
    for x in range(w):
        if data[(y, x)] == -1:
            s += "#"
        else:
            s += str(data[(y, x)])
    print(s)

H, W = list(map(int, input().split()))
Map = ["." * (W + 2)]
for i in range(H):
    line = "." + eval(input()) + "."
    x = []
    for j in range(W + 2):
        x.append(line[j])
    Map.append(x)
Map.append("." * (W + 2))
for h in range(1, 1 + H):
    for w in range(1, 1 + W):
        if Map[h][w] == ".":
            cnt = 0
            for i, j in [
                (-1, -1),
                (-1, 0),
                (0, -1),
                (1, -1),
                (-1, 1),
                (1, 0),
                (0, 1),
                (1, 1),
            ]:
                if Map[h + i][w + j] == "#":
                    cnt += 1
            Map[h][w] = str(cnt)
for h in range(1, 1 + H):
    print(("".join(Map[h][1:-1])))

-h, w = list(map(int, input().split())) -from collections import defaultdict - -data = defaultdict(int) -for y in range(h): -    line = eval(input()) -    for x in range(w): -        if line[x] == "#": -            data[(y, x)] = -1 -            for i in range(-1, 2): -                for j in range(-1, 2): -                    if data[(y + i, x + j)] != -1: -                        data[(y + i, x + j)] += 1 -for y in range(h): -    s = "" -    for x in range(w): -        if data[(y, x)] == -1: -            s += "#" -        else: -            s += str(data[(y, x)]) -    print(s) +H, W = list(map(int, input().split())) +Map = ["." * (W + 2)] +for i in range(H): +    line = "." + eval(input()) + "." +    x = [] +    for j in range(W + 2): +        x.append(line[j]) +    Map.append(x) +Map.append("." * (W + 2)) +for h in range(1, 1 + H): +    for w in range(1, 1 + W): +        if Map[h][w] == ".": +            cnt = 0 +            for i, j in [ +                (-1, -1), +                (-1, 0), +                (0, -1), +                (1, -1), +                (-1, 1), +                (1, 0), +                (0, 1), +                (1, 1), +            ]: +                if Map[h + i][w + j] == "#": +                    cnt += 1 +            Map[h][w] = str(cnt) +for h in range(1, 1 + H): +    print(("".join(Map[h][1:-1])))