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 ? '#' : [].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]])).filter(x => x).length).join('')).join('\n');

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