#include<bits/stdc++.h>
using namespace std;
int n,a[32][32];
int lx[4]={0,1,0,-1};
int ly[4]={1,0,-1,0};
void SB(int x,int y)
{
a[x][y] = -1;
for(int i = 0; i < 4;i++)
{
int tx = x + lx[i];
int ty = y + ly[i];
if(tx >= 1 && tx <= n && ty >= 1 && ty <= n && a[tx][ty] == 0)
{
SB(tx,ty);
}
}
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n;j++)
{
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1;j <= n; j++)
{
if((i == 1||i == n||j == 1 || j == n) && a[i][j] == 0)
{
SB(i,j);
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1;j <= n; j++)
{
if(a[i][j] == -1) cout << 0 << " ";
else if(a[i][j] == 1) cout << 1 << " ";
else if(a[i][j] == 0) cout << 2 << " ";
}
cout << endl;
}
return 0;
}
/**************************************************************
Problem: 1802
User: yangwanning
Language: C++
Result: Accepted
Time:18 ms
Memory:2076 kb
****************************************************************/