const main = input => input.split('\n').slice(1).filter(x => x).map(line => line.split('').map(x => x === '#' ? 1 : 0)).map((vs, i, matrix) => vs.map((v, j) => v ? '#' : [i - 1, i, i + 1].filter(x => matrix[x]).map(x => [j - 1, j, j + 1].filter(y => matrix[x][y]).length).reduce((a, b) => a + b)).join('')).join('\n');

console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')));
