#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
//int cellTypes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
int getCellType(int x, int y, const vector<vector<int>>& maze, int N) {
int top = (y > 0 && maze[y - 1][x] == -1) ? 1 : 0;
int bottom = (y < N - 1 && maze[y + 1][x] == -1) ? 1 : 0;
int left = (x > 0 && maze[y][x - 1] == -1) ? 1 : 0;
int right = (x < N - 1 && maze[y][x + 1] == -1) ? 1 : 0;
//int cellType = (top << 3) | (bottom << 2) | (left << 1) | right;
int cellType = 0;
if (left && !top && !bottom && !right) cellType = 1;
else if (!left && top && !bottom && !right) cellType = 2;
else if (left && top && !bottom && !right) cellType = 3;
else if (!left && !top && !bottom && right) cellType = 4;
else if (left && !top && !bottom && right) cellType = 5;
else if (!left && top && !bottom && right) cellType = 6;
else if (left && top && !bottom && right) cellType = 7;
else if (!left && !top && bottom && !right) cellType = 8;
else if (left && !top && bottom && !right) cellType = 9;
else if (!left && top && bottom && !right) cellType = 10;
else if (left && top && bottom && !right) cellType = 11;
else if (!left && !top && bottom && right) cellType = 12;
else if (left && !top && bottom && right) cellType = 13;
else cellType = 14;
//int cellType = cellTypes[left + top * 2 + bottom * 4 + right * 8 - 1];
return cellType;
}
int main() {
int N;
char comma;
cin >> N >> comma >> N;
vector<vector<int>> maze(N, vector<int>(N));
string line;
cin.ignore();
for (int i = 0; i < N; ++i) {
getline(cin, line);
stringstream ss(line);
string cell;
for (int j = 0; j < N; ++j) {
getline(ss, cell, ',');
maze[i][j] = stoi(cell);
}
}
for (int y = 0; y < N; ++y) {
for (int x = 0; x < N; ++x) {
if (maze[y][x] == 0) {
int cellType = getCellType(x, y, maze, N);
maze[y][x] = cellType;
}
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cout << maze[i][j];
if (j != N - 1) cout << ",";
}
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9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AgIGdldGxpbmUoY2luLCBsaW5lKTsKICAgICAgICBzdHJpbmdzdHJlYW0gc3MobGluZSk7CiAgICAgICAgc3RyaW5nIGNlbGw7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBOOyArK2opIHsKICAgICAgICAgICAgZ2V0bGluZShzcywgY2VsbCwgJywnKTsKICAgICAgICAgICAgbWF6ZVtpXVtqXSA9IHN0b2koY2VsbCk7CiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IHkgPSAwOyB5IDwgTjsgKyt5KSB7CiAgICAgICAgZm9yIChpbnQgeCA9IDA7IHggPCBOOyArK3gpIHsKICAgICAgICAgICAgaWYgKG1hemVbeV1beF0gPT0gMCkgewogICAgICAgICAgICAgICAgaW50IGNlbGxUeXBlID0gZ2V0Q2VsbFR5cGUoeCwgeSwgbWF6ZSwgTik7CiAgICAgICAgICAgICAgICBtYXplW3ldW3hdID0gY2VsbFR5cGU7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBOOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IE47ICsraikgewogICAgICAgICAgICBjb3V0IDw8IG1hemVbaV1bal07CiAgICAgICAgICAgIGlmIChqICE9IE4gLSAxKSBjb3V0IDw8ICIsIjsKICAgICAgICB9CiAgICAgICAgY291dCA8PCBlbmRsOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==