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

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

b = [[0 for _ in range(w)]for _ in range(h)]

H = [-1,-1,-1, 0, 0, 1, 1, 1]

W = [-1, 0, 1,-1, 1,-1, 0, 1]

for i in range(h):

    for j in range(w):

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

            b[i][j] = "#"

            for k in range(len(H)):

                if i+H[k] < 0 or i+H[k] >= h:continue

                elif j+W[k] < 0 or j+W[k] >= w:continue

                elif a[i+H[k]][j+W[k]] == "#":continue

                b[i+H[k]][j+W[k]] += 1

for i in range(h):

    print(*b[i],sep="")

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

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

a.insert(0,"."*(w+2))

a.append("."*(w+2))

y = [1,1, 1,-1,-1,-1,0, 0]

x = [0,1,-1, 0, 1,-1,1,-1]

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

    l =[]

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

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

            l += "#"

        else: l += str(sum([1 for k in range(8) if a[i+y[k]][j+x[k]] == "#"]))

    print(("".join(l)))
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]
H = [-1, -1, -1, 0, 0, 1, 1, 1]
W = [-1, 0, 1, -1, 1, -1, 0, 1]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            b[i][j] = "#"
            for k in range(len(H)):
                if i + H[k] < 0 or i + H[k] >= h:
                    continue
                elif j + W[k] < 0 or j + W[k] >= w:
                    continue
                elif a[i + H[k]][j + W[k]] == "#":
                    continue
                b[i + H[k]][j + W[k]] += 1
for i in range(h):
    print(*b[i], sep="")

h, w = list(map(int, input().split()))
a = ["." + eval(input()) + "." for _ in range(h)]
a.insert(0, "." * (w + 2))
a.append("." * (w + 2))
y = [1, 1, 1, -1, -1, -1, 0, 0]
x = [0, 1, -1, 0, 1, -1, 1, -1]
for i in range(1, h + 1):
    l = []
    for j in range(1, w + 1):
        if a[i][j] == "#":
            l += "#"
        else:
            l += str(sum([1 for k in range(8) if a[i + y[k]][j + x[k]] == "#"]))
    print(("".join(l)))

-h, w = map(int, input().split()) -a = [list(input()) for _ in range(h)] -b = [[0 for _ in range(w)] for _ in range(h)] -H = [-1, -1, -1, 0, 0, 1, 1, 1] -W = [-1, 0, 1, -1, 1, -1, 0, 1] -for i in range(h): -    for j in range(w): +h, w = list(map(int, input().split())) +a = ["." + eval(input()) + "." for _ in range(h)] +a.insert(0, "." * (w + 2)) +a.append("." * (w + 2)) +y = [1, 1, 1, -1, -1, -1, 0, 0] +x = [0, 1, -1, 0, 1, -1, 1, -1] +for i in range(1, h + 1): +    l = [] +    for j in range(1, w + 1): -            b[i][j] = "#" -            for k in range(len(H)): -                if i + H[k] < 0 or i + H[k] >= h: -                    continue -                elif j + W[k] < 0 or j + W[k] >= w: -                    continue -                elif a[i + H[k]][j + W[k]] == "#": -                    continue -                b[i + H[k]][j + W[k]] += 1 -for i in range(h): -    print(*b[i], sep="") +            l += "#" +        else: +            l += str(sum([1 for k in range(8) if a[i + y[k]][j + x[k]] == "#"])) +    print(("".join(l)))