import scala.io.StdIn._
object Main extends App {


  val n = readInt()
  val nodes = Array.fill(n * n){Nil: List[Int]}
  for (_ ← 0 until 2 * n * n - 2 * n){
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    nodes(a - 1) ::= b - 1
    nodes(b - 1) ::= a - 1
  }
  println(
    makeMap(n, nodes).map{_.map{_ + 1}.mkString(" ")}.mkString("\n")
  )





  def makeMap(n: Int, info: Array[List[Int]]): Array[Array[Int]] = {
    val counts = info.map{_.length}
    val result = Array.fill(n){Array.fill(n){-1}}
    var position = Point(0, 0)
    var dir = Point(1, 0)
    var current = info.indexWhere(_.length == 2)
    for (i ← 0 until n * n) {
      counts(current) = -1
      result(position.y)(position.x) = current
      for (neighbor ← info(current)) {
        counts(neighbor) -= 1
      }
      var nextPosition = position + dir
      if (!result.indices.contains(nextPosition.x) || !result.indices.contains(nextPosition.y) || result(nextPosition.y)(nextPosition.x) >= 0) {
        dir = dir.rotateRight
        nextPosition = position + dir
      }
      if (i != n * n - 1) {
        val minCount = info(current).map(s ⇒ counts(s)).filter(_ >= 0).min
        current = info(current).filter(suspect ⇒ counts(suspect) == minCount && nextPosition.neighbors.filter(neighbor ⇒ result.indices.contains(neighbor.x) && result.indices.contains(neighbor.y) && result(neighbor.y)(neighbor.x) != -1).forall(neighbor ⇒ info(suspect).contains(result(neighbor.y)(neighbor.x)))).minBy(s ⇒ info(s).length)
        position = nextPosition
      }
    }
    result
  }
  case class Point(x: Int, y: Int) {
    def +(other: Point): Point = Point(x + other.x, y + other.y)
    def rotateRight: Point = Point(-y, x)
    def neighbors: List[Point] = List(Point(x + 1, y), Point(x - 1, y), Point(x, y + 1), Point(x, y - 1))
  }
}
