Problem: Intersections of Crossing Path City are aligned to a grid. There are $N$ east-west streets which are numbered from 1 to $N$, from north to south. There are also $N$ north-south streets which are numbered from 1 to $N$, from west to east. Every pair of east-west and north-south streets has an intersection; therefore there are $N^2$ intersections which are numbered from 1 to $N^2$.

Surprisingly, all of the residents in the city are Ninja. To prevent outsiders from knowing their locations, the numbering of intersections is shuffled.

You know the connections between the intersections and try to deduce their positions from the information. If there are more than one possible set of positions, you can output any of them.



Input

The input consists of a single test case formatted as follows.


$N$
$a_1$ $b_1$
...
$a_{2N^2−2N}$ $\;$ $b_{2N^2−2N}$


The first line consists of an integer $N$ ($2 \leq N \leq 100$). The following $2N^2 - 2N$ lines represent connections between intersections. The ($i+1$)-th line consists of two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq N^2, a_i \ne b_i$), which represent that the $a_i$-th and $b_i$-th intersections are adjacent. More precisely, let's denote by ($r, c$) the intersection of the $r$-th east-west street and the $c$-th north-south street. If the intersection number of ($r,c$) is $a_i$ for some $r$ and $c$, then the intersection number of either ($r-1, c$), ($r+1, c$), ($r, c-1$) or ($r, c+1$) must be $b_i$. All inputs of adjacencies are different, i.e., ($a_i, b_i$) $\ne$ ($a_j, b_j$) and ($a_i, b_i$) $\ne$ ($b_j, a_j$) for all $1 \leq i < j \leq 2N^2-2N$. This means that you are given information of all adjacencies on the grid.

The input is guaranteed to describe a valid map.

Output

Print a possible set of positions of the intersections. More precisely, the output consists of $N$ lines each of which has space-separated $N$ integers. The $c$-th integer of the $r$-th line should be the intersection number of ($r, c$).

If there are more than one possible set of positions, you can output any of them.

Examples

Input

3
1 2
4 7
8 6
2 3
8 9
5 3
4 6
5 6
7 8
1 4
2 6
5 9


Output

7 4 1
8 6 2
9 5 3


Input

4
12 1
3 8
10 7
13 14
8 2
9 12
6 14
11 3
3 13
1 10
11 15
4 15
4 9
14 10
5 7
2 5
6 1
14 5
16 11
15 6
15 13
9 6
16 4
13 2


Output

8 2 5 7
3 13 14 10
11 15 6 1
16 4 9 12

Solution (in CPP):

Solution:
#include <iostream>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
const int inf=10000000;
int n;
bool visited[10005];
int deg[10005];
vi deglist[3];
vi g[10005];
int ans[105][105];
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(int argc,char const* argv[])
{
  cin >> n;
  memset(visited,false,sizeof(visited));
  memset(deg,0,sizeof(deg));
  memset(ans,0,sizeof(ans));
  for(int i=0;i<2*n*(n-1);i++)
    {
      int a,b;
      cin >> a >> b;
      a--;
      b--;
      deg[a]++;
      deg[b]++;
      g[a].push_back(b);
      g[b].push_back(a);
    }
  for(int i=0;i<10005;i++)
    {
      if(deg[i]==2) deglist[0].push_back(i);
      else if(deg[i]==3) deglist[1].push_back(i);
      else if(deg[i]==4) deglist[2].push_back(i);
    }
  int twodind=0;
  ans[0][0]=deglist[0][twodind];
  int pretwo=ans[0][0];
  twodind++;
  if(n==2)
    {
      ans[0][1]=g[pretwo][0];
      visited[g[pretwo][0]]=true;;
      ans[1][0]=g[pretwo][1];
      visited[g[pretwo][1]]=true;
      for(int i=0;i<deglist[0].size();i++)
	{
	  if(!visited[deglist[0][i]])
	    {
	      ans[1][1]=deglist[0][i];
	      break;
	    }
	}
    }
  for(int x=1;x<n;x++)
    {
      int prev=ans[0][x-1];
      if(x!=n-1)
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==3 && !visited[g[prev][k]])
		{
		  ans[0][x]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		  break;
		}
	    }
	}
      else
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==2 &&!visited[g[prev][k]])
		{
		  ans[0][x]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		}
	    }
	}
    }
  for(int y=1;y<n;y++)
    {
      int prev=ans[y-1][n-1];
      if(y!=n-1)
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==3 && !visited[g[prev][k]])
		{
		  ans[y][n-1]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		  break;
		}
	    }
	}
      else
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==2 && !visited[g[prev][k]])
		{
		  ans[y][n-1]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		}
	    }
	}
    }
  for(int x=n-2;x>=0;x--)
    {
      int prev=ans[n-1][x+1];
      if(x!=0)
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==3 &&!visited[g[prev][k]])
		{
		  ans[n-1][x]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		  break;
		}
	    }
	}
      else
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==2 &&!visited[g[prev][k]])
		{
		  ans[n-1][x]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		}
	    }
	}
    }
  for(int y=n-2;y>=0;y--)
    {
      int prev=ans[y+1][0];
      if(y!=0)
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==3 &&!visited[g[prev][k]])
		{
		  ans[y][0]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		  break;
		}
	    }
	}
      else
	{
	  for(int k=0;k<g[prev].size();k++)
	    {
	      if(deg[g[prev][k]]==2 && !visited[g[prev][k]])
		{
		  ans[y][0]=g[prev][k];
		  visited[g[prev][k]]=true;
		  //g[prev].erase(g[prev].begin()+k);
		}
	    }
	}
    }
  if(n>=3)
    {
      for(int y=1;y<n-1;y++)
	{
	  for(int x=1;x<n-1;x++)
	    {
	      int prev1=ans[y-1][x];
	      int prev2=ans[y][x-1];
	      bool get=false;
	      for(int k1=0;k1<g[prev1].size();k1++)
		{
		  for(int k2=0;k2<g[prev2].size();k2++)
		    {
		      if(g[prev1][k1]==g[prev2][k2] && !visited[g[prev1][k1]])
			{
			  ans[y][x]=g[prev1][k1];
			  visited[g[prev1][k1]]=true;
			  get=true;
			  break;
			}
		    }
		  if(get) break;
		}
	    }
	}
    }
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	{
	  if(j!=n-1)
	    {
	      cout << ans[i][j]+1 << ' ';
	    }
	  else
	    {
	      cout << ans[i][j]+1 << endl;
	    }
	}
    }
    
  return 0;
}