#include<bits/stdc++.h>
using namespace std;
int a,l[1000][1000],h[1000][1000],ci;
int is1(int x,int y)
{
if(h[x][y]==-1)
return 0;
else if(h[x][y]==1)
return 1;
else if(l[x][y])
return 1;
else if(x<1 or y<1 or x>a or y>a)
return 0;
else
{
bool s=1;
h[x][y]=1;
if(!h[x][y-1])
s&=is1(x,y-1);
if(!h[x][y+1])
s&=is1(x,y+1);
if(!h[x-1][y])
s&=is1(x-1,y);
if(!h[x+1][y])
s&=is1(x+1,y);
if(s==0 or (l[x+1][y]==0 or h[x+1][y]==-1 and l[x][y+1]==0 or h[x][y+1]==-1 and l[x-1][y]==0 or h[x-1][y]==-1 and l[x][y-1]==0 or h[x][y-1]==-1 ))
h[x][y]=-1;
for(int i=1;i<=a;i++)
{
for(int j=1;j<=a;j++)
{
if(h[i][j]==1)
l[i][j]=2;
if(h[i][j]==-1)
l[i][j]=0;
}
}
return s;
}
}
int main()
{
cin>>a;
for(int i=1;i<=a;i++)
for(int j=1;j<=a;j++)
cin>>l[i][j];
for(int i=1;i<=a;i++)
for(int j=1;j<=a;j++)
is1(i,j);
for(int i=1;i<=a;i++)
{
for(int j=1;j<=a;j++)
cout<<l[i][j]<<" ";
cout<<endl;
}
}