#include <iostream>
#include <vector>
using namespace std;

bool check(int row, int col, int n, vector<vector<int>>& maze,
           vector<vector<bool>>& visited) {
    return (row >= 0 && col >= 0 && row < n && col < n &&
            maze[row][col] == 1 && !visited[row][col]);
}

void ratInMaze(int row, int col, int n, vector<vector<int>>& maze,
               vector<vector<bool>>& visited,vector<vector<int>>& result) {

    if (row == n-1 && col == n-1) {
        paths.push_back(path);
        result[row][col] = 1;
        return;
    }

    visited[row][col] = true;
    result[row][col] = 1;

    if (check(row + 1, col, n, maze, visited)) {
        ratInMaze(row + 1, col, n, maze, visited, result);
    }
    if (check(row - 1, col, n, maze, visited)) {
        ratInMaze(row - 1, col, n, maze, visited, result);
    }
    if (check(row, col + 1, n, maze, visited)) {
        ratInMaze(row, col + 1, n, maze, visited, result);
    }
    if (check(row, col - 1, n, maze, visited)) {
        ratInMaze(row, col - 1, n, maze, visited, result);
    }

    visited[row][col] = false;
    result[row][col] = 0;  // backtrack
}

int main() {
    int n;
    cin >> n;

    vector<vector<int>> maze(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> maze[i][j];
        }
    }

    vector<vector<bool>> visited(n, vector<bool>(n, false));
    vector<string> paths;
    vector<vector<int>> result(n, vector<int>(n, 0));

    if (maze[0][0] == 1) {
        ratInMaze(0, 0, n, maze, visited, result);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << result[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}