import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
char[][] bombArray=new char[n][n];
char[][] result=new char[n][n];
for (int i = 0; i < n; i++) {
bombArray[i]=br.readLine().toCharArray(); // 지뢰의 위치 ( .은 지뢰가 없는 지점, *는 지뢰가 있는 지점)
// 지뢰가 있는 지점을 건드리면 플레이어가 진다.
// 지뢰가 없는 지점을 건드리면 인접한 8개의 칸에 지뢰가 몇개 있는지 알려주는 숫자가 나타난다.
}
for (int i = 0; i < n; i++) {
result[i]=br.readLine().toCharArray(); // 문자열 입력 (x는 이미 열린 칸, .은 열리지 않은 칸)
}
int[] dxs = {-1,-1,-1,0,0,1,1,1};
int[] dys= {-1, 0, 1, -1, 1, -1, 0, 1};
boolean button=false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (result[i][j]=='.') {
continue;
}
if (bombArray[i][j]=='.') { // 지뢰가 없는 지점
int temp=0; // 현재 위치에 인접해있는 지뢰의 개수
for (int k = 0; k < 8; k++) {
int nx=i+dxs[k];
int ny=j+dys[k];
if(0<=nx && nx<n && 0<=ny && ny<n) {
if(bombArray[nx][ny]=='*') {
temp+=1;
}
}
}
result[i][j]=(char)(temp+'0');
}else { // 지뢰가 있는 지점
button=true;
}
}
}
if (button) { // 지뢰가 있는 모든 칸이 별표로 표시되어야한다.
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(bombArray[i][j]=='*') {
result[i][j]='*';
}
}
}
}
StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
sb.append(result[i][j]);
}
sb.append("\n");
}
System.out.print(sb);
}
}