#include <bits/stdc++.h>
#define rand() dis(gen)
using namespace std;

int i, j, n, a[30][30], N;
bool ok;
mt19937 gen(time(0));
uniform_int_distribution<int> dis(0, 1e6);

void solve(int x, int y) {
  if(y == n * n) {
    solve(x + 1, 0);
    return;
  }

  if(x == n * n) {
    ok = 1;
    for(int i = 0; i < N; ++i)
      for(int j = 0; j < N; ++j)
        cout << a[i][j] << " \n"[j == N - 1];
    return;
  }

  if(a[x][y]) {
    solve(x, y + 1);
    return;
  }

  set<int> S;
  for(int i = 0; i < N; ++i) {
    if(a[x][i]) S.insert(a[x][i]);
    if(a[i][y]) S.insert(a[i][y]);
  }

  for(int i = x - (x % n); i < x - (x % n) + n; ++i)
    for(int j = y - (y % n); j < y - (y % n) + n; ++j)
      if(a[i][j]) S.insert(a[i][j]);

  vector<int> v;
  v.reserve(S.size());
  for(int i = 1; i <= N; ++i)
    if(!S.count(i)) v.push_back(i);

  while(v.size()) {
    int poz = rand() % v.size();
    a[x][y] = v[poz];
    solve(x, y + 1);
    if(ok) return; 
    a[x][y] = 0;
    swap(v[poz], v[v.size() - 1]);
    v.pop_back();
  }
}

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n; N = n * n;
  for(i = 0; i < N; ++i)
    for(j = 0; j < N; ++j)
      cin >> a[i][j];

  solve(0, 0);

  return 0;
}