import numpy as np

import scipy as sp

from scipy import signal



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

A = []

for i in range(H):

  A.append(list(input()))



B = np.array(A)

B = np.where(B=="#",1,B)

B = np.where(B==".",0,B)

B = B.astype("int32")



s = np.ones(9).reshape(3,3)

s[1][1]=0



C = sp.signal.convolve2d(B,s,"same").astype("int32")



for h in range(H):

  for w in range(W):

    if A[h][w] == "#":

      print("#",end="")

    elif A[h][w] == ".":

      print(C[h][w],end="")

  print("")

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

A = []

for i in range(H):

  A.append(list(input()))



for h in range(H):

  for w in range(W):

    if A[h][w] == "#":

      print("#",end="")

    elif A[h][w] == ".":

      c = 0 

      for i in range(-1,2):

        for j in range(-1,2):

          if 0<=h+i<=H-1 and 0<=w+j<=W-1 and A[h+i][w+j]=="#":

            c+=1

      print(c,end="")

  print("")

import numpy as np
import scipy as sp
from scipy import signal

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(input()))
B = np.array(A)
B = np.where(B == "#", 1, B)
B = np.where(B == ".", 0, B)
B = B.astype("int32")
s = np.ones(9).reshape(3, 3)
s[1][1] = 0
C = sp.signal.convolve2d(B, s, "same").astype("int32")
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            print("#", end="")
        elif A[h][w] == ".":
            print(C[h][w], end="")
    print("")

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(input()))
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            print("#", end="")
        elif A[h][w] == ".":
            c = 0
            for i in range(-1, 2):
                for j in range(-1, 2):
                    if (
                        0 <= h + i <= H - 1
                        and 0 <= w + j <= W - 1
                        and A[h + i][w + j] == "#"
                    ):
                        c += 1
            print(c, end="")
    print("")

-import numpy as np -import scipy as sp -from scipy import signal - -B = np.array(A) -B = np.where(B == "#", 1, B) -B = np.where(B == ".", 0, B) -B = B.astype("int32") -s = np.ones(9).reshape(3, 3) -s[1][1] = 0 -C = sp.signal.convolve2d(B, s, "same").astype("int32") -            print(C[h][w], end="") +            c = 0 +            for i in range(-1, 2): +                for j in range(-1, 2): +                    if ( +                        0 <= h + i <= H - 1 +                        and 0 <= w + j <= W - 1 +                        and A[h + i][w + j] == "#" +                    ): +                        c += 1 +            print(c, end="")