#include <iostream>
//#include <fstream>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>

using namespace std;

//ifstream cin ("x.in"); ofstream cout ("x.out");

const int nmax = 25;

bool gata;
int n, m;
int col[nmax + 1], lin[nmax + 1];
int v[nmax + 1][nmax + 1];
int fc[nmax + 1][nmax + 1], fl[nmax + 1][nmax + 1];
int w[nmax + 1][nmax + 1];

void bck (int ln) {
    if (ln == n + 1) {
        for (int i = 1; i <= n; ++ i) {
            for (int j = 1; j <= n; ++ j) {
                cout << v[ i ][ j ] << " ";
            }
            cout << "\n";
        }
        gata = 1;
        return ;
    }

    if (gata) return ;

    int pos;
    for (int x = 1; x <= n; ++ x) {
        if (v[ ln ][ x ] == 0) {
            pos = x; break;
        }
    }

    -- lin[ ln ];

    int nxt = ln;
    if (lin[ ln ] == 0) {
        nxt = 1;
        while (nxt <= n && lin[ nxt ] == 0) ++ nxt;
    }

    int c = ((ln - 1) / m) * m + ((pos - 1) / m);

    for (int k = 1; k <= n; ++ k) {
        if (fl[ ln ][ k ] == 0 && fc[ pos ][ k ] == 0 && w[ c ][ k ] == 0) {
            fc[ pos ][ k ] = 1;
            fl[ ln ][ k ] = 1;
            w[ c ][ k ] = 1;
            -- col[ pos ];

            v[ ln ][ pos ] = k;
            bck( nxt );

            w[ c ][ k ] = 0;
            v[ ln ][ pos ] = 0;
            ++ col[ pos ];

            if (gata) return ;

            fc[ pos ][ k ] = fl[ ln ][ k ] = 0;
        }
    }
    ++ lin[ ln ];
}

int main() {
    cin >> n;
    m = n;
    n *= n;

    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= n; ++ j) {
            cin >> v[ i ][ j ];
            lin[ i ] += (v[ i ][ j ] == 0);
            col[ j ] += (v[ i ][ j ] == 0);

            if (v[ i ][ j ] > 0) {
                int c = ((i - 1) / m) * m + ((j - 1) / m);
                w[ c ][ v[ i ][ j ] ] =1;
                fc[ j ][ v[ i ][ j ] ] = 1;
                fl[ i ][ v[ i ][ j ] ] = 1;
            }
        }
    }

    int lmn = 1;
    for (int i = 1; i <= n; ++ i) {
        if (lin[ i ] < lin[ lmn ]) {
            lmn = i;
        }
    }
    bck( lmn );

    return 0;
}