#include <bits/stdc++.h>
using namespace std;
int a[35][35];
int mk[35][35];
int n;
int x, y;
typedef pair<int, int>PII;
int xy[4][2] = {(1, 0), (-1, 0), (0, -1), (0, 1)};
void bfs(int x, int y) {
queue <PII>q;
q.push(make_pair(x, y));
while (q.size()) {
PII f = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int xx = f.first + xy[i][0], yy = f.second + xy[i][1];
if (xx >= 1 && xx <= n && yy >= 1 && yy <= n && !mk[xx][yy] && !a[xx][yy]) {
mk[xx][yy] = 1;
q.push(make_pair(xx, yy));
}
}
}
}
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 ) {
if (!a[i][j]) {
bfs(i, j);
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (mk[i][j]) {
cout << 0 ;
} else if (a[i][j]) {
cout << 1;
} else {
cout << 2 ;
}
cout << " ";
}
cout << endl;
}
return 0;
}