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

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