#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;

	vvi v(n, vi(n, -1));
	int m = 2 * n * n - 2 * n;
	vi a(m), b(m);
	vvi cnt(n * n);
	REP(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		cnt[a[i]].push_back(b[i]);
		cnt[b[i]].push_back(a[i]);
	}
	vi used(m, 0);
	REP(i, n)REP(j, n) {
		int c = 2;
		if (i % (n - 1) != 0)c++;
		if (j % (n - 1) != 0)c++;
		REP(k, n * n) {
			if (cnt[k].size() != c || used[k] == 1)continue;
			bool ok = true;
			if (i > 0)if (find(ALL(cnt[k]), v[i - 1][j]) == cnt[k].end())ok = false;
			if (j > 0)if (find(ALL(cnt[k]), v[i][j - 1]) == cnt[k].end())ok = false;
			if (ok) {
				used[k] = 1;
				v[i][j] = k;
				break;
			}
		}
	}
	REP(i, n)REP(j, n) {
		cout << v[i][j] + 1 << " \n"[j == n - 1];
	}
}
