#include <iostream>
#include <queue>
using namespace std;
int n;
int a[31][31];
int v[31][31];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct node
{
int x;
int y;
}st,tx;
queue <node> q;
int bfs(int x,int y)
{
st.x=x;
st.y=y;
v[x][y]=1;
q.push(st);
while(!q.empty())
{
st=q.front();
q.pop();
for(int i=0;i<4;i++){
tx.x=st.x+dx[i];
tx.y=st.y+dy[i];
if(a[tx.x][tx.y]==0&&v[tx.x][tx.y]==0&&tx.x>=0&&tx.x<=n+1&&tx.y>=0&&tx.y<=n+1){
v[tx.x][tx.y]=1;
q.push(tx);
}
}
}
}
int main()
{
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
bfs(0,0);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(v[i][j]==0&&a[i][j]==0){
a[i][j]=2;
}
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}