n, m = io.read('n'), io.read('n'), io.read('l')
s = {}
for i = 1, n do s[i] = io.read('l') end
ans = {}
for i = 1, n do ans[i] = {} end

local BAKU = 35
local AKI = 46
local MOV = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}

for i = 1, n do
    for j = 1, m do
        if s[i]:byte(j) == AKI then
            local count = 0
            for k = 1, #MOV do
                local ni, nj = i + MOV[k][1], j + MOV[k][2]
                if ni >= 1 and ni <= n and nj >= 1 and nj <= m and
                    s[ni]:byte(nj) == BAKU
                then
                    count = count + 1
                end
            end
            ans[i][j] = string.char(48 + count)
        else
            ans[i][j] = '#'
        end
    end
end

for i = 1, n do
    for j = 1, m do io.write(ans[i][j]) end
    io.write('\n')
end
