#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<vector<int>> G(N*N);
    vector<int> used(N*N);
    vector<int> outdeg(N*N);
    for(int i = 0; i < 2*N*N - 2*N; i++){
        int a,b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        
        outdeg[a]++;
        outdeg[b]++;
    }
    res = vector<vector<int>>(N,vector<int>(N,-1));
    int u = (int)(min_element(outdeg.begin(), outdeg.end())-outdeg.begin());
    res[0][0] = u;
    res[0][1] = G[u][0]; res[1][0] = G[u][1];
    
    used[u] = used[G[u][0]] = used[G[u][1]] = 1;
    
    // 一列目と一行目は矛盾が生じないように揃える
    for(int j = 2; j < N;j++){
        if(j != N-1){
            for(auto v:G[res[0][j-1]]) if(!used[v] && outdeg[v] == 3) { res[0][j] = v; used[v] = true; break; }
        }else{
            for(auto v:G[res[0][j-1]]) if(!used[v] && outdeg[v] == 2) { res[0][j] = v; used[v] = true; break; }
        }
    }
    for(int i = 2; i < N;i++){
        if(i != N-1){
            for(auto v:G[res[i-1][0]]) if(!used[v] && outdeg[v] == 3) { res[i][0] = v; used[v] = true; break; }
        }else{
            for(auto v:G[res[i-1][0]]) if(!used[v] && outdeg[v] == 2) { res[i][0] = v; used[v] = true; break; }
        }
    }
    // 残りを埋めていく
    for(int i = 1; i < N;i++){
        for(int j = 1; j < N;j++){
            for(auto cand:G[res[i-1][j]]){
                if(used[cand]) continue;
                res[i][j] = cand;
                used[cand] = true;
                break;
            }
        }
    }
    
    for(auto& vec:res) for(auto& v:vec) v++;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<vector<vector<int>>>() << endl;
    return 0;
}



Measured memory_bytes: 3660