y, x= list(map(int,input().split()))

bomb = [0 for i in range(y)]

ary = [[0 for i in range(x)]for i in range(y)]



for i in range(y):

    bomb[i] = list(eval(input()))



for a in range(y):

    for b in range(x):

        if bomb[a][b] == "#":

            ary[a][b] = "#"

        else :

            ary[a][b] = 0

# この配列を用意することによって’＃’の周りの計算を楽にできるようになる

height_ary =[-1,-1,-1, 0,0, 1,1,1]

width_ary  =[-1, 0 ,1,-1,1,-1,0,1]



for a in range(y):

    for b in range(x):

        if ary[a][b] == "#":

            for i in range(8):

                h = height_ary[i] + a

                w = width_ary [i] + b

                if h < 0 or h >= y: continue

                if w < 0 or w >= x: continue

                if not ary[h][w] == "#":

                    ary[h][w] += 1



for i in range(y):

    result = list(map(str,ary[i]))

    print(("".join(result)))
h, w = list(map(int,input().split()))

a = [eval(input()) for _ in range(h)]

for i in range(h):

    l =""

    for j in range(w):

        if a[i][j] == "#":

            l += "#"

        else:

            l+=str(sum([s[max(0,j-1):min(w,j+2)].count("#") for s in a[max(0,i-1):min(h,i+2)]]))

    print(l)
y, x = list(map(int, input().split()))
bomb = [0 for i in range(y)]
ary = [[0 for i in range(x)] for i in range(y)]
for i in range(y):
    bomb[i] = list(eval(input()))
for a in range(y):
    for b in range(x):
        if bomb[a][b] == "#":
            ary[a][b] = "#"
        else:
            ary[a][b] = 0
# この配列を用意することによって’＃’の周りの計算を楽にできるようになる
height_ary = [-1, -1, -1, 0, 0, 1, 1, 1]
width_ary = [-1, 0, 1, -1, 1, -1, 0, 1]
for a in range(y):
    for b in range(x):
        if ary[a][b] == "#":
            for i in range(8):
                h = height_ary[i] + a
                w = width_ary[i] + b
                if h < 0 or h >= y:
                    continue
                if w < 0 or w >= x:
                    continue
                if not ary[h][w] == "#":
                    ary[h][w] += 1
for i in range(y):
    result = list(map(str, ary[i]))
    print(("".join(result)))

h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
for i in range(h):
    l = ""
    for j in range(w):
        if a[i][j] == "#":
            l += "#"
        else:
            l += str(
                sum(
                    [
                        s[max(0, j - 1) : min(w, j + 2)].count("#")
                        for s in a[max(0, i - 1) : min(h, i + 2)]
                    ]
                )
            )
    print(l)

-y, x = list(map(int, input().split())) -bomb = [0 for i in range(y)] -ary = [[0 for i in range(x)] for i in range(y)] -for i in range(y): -    bomb[i] = list(eval(input())) -for a in range(y): -    for b in range(x): -        if bomb[a][b] == "#": -            ary[a][b] = "#" +h, w = list(map(int, input().split())) +a = [eval(input()) for _ in range(h)] +for i in range(h): +    l = "" +    for j in range(w): +        if a[i][j] == "#": +            l += "#" -            ary[a][b] = 0 -# この配列を用意することによって’＃’の周りの計算を楽にできるようになる -height_ary = [-1, -1, -1, 0, 0, 1, 1, 1] -width_ary = [-1, 0, 1, -1, 1, -1, 0, 1] -for a in range(y): -    for b in range(x): -        if ary[a][b] == "#": -            for i in range(8): -                h = height_ary[i] + a -                w = width_ary[i] + b -                if h < 0 or h >= y: -                    continue -                if w < 0 or w >= x: -                    continue -                if not ary[h][w] == "#": -                    ary[h][w] += 1 -for i in range(y): -    result = list(map(str, ary[i])) -    print(("".join(result))) +            l += str( +                sum( +                    [ +                        s[max(0, j - 1) : min(w, j + 2)].count("#") +                        for s in a[max(0, i - 1) : min(h, i + 2)] +                    ] +                ) +            ) +    print(l)