require 'set'

n = gets.to_i
g = (0..n*n).map { Set.new }
(2 * n * n - 2 * n).times do
  i, j = gets.split.map(&:to_i)
  g[i] << j
  g[j] << i
end

row = [(1..n*n).find {|i| g[i].size == 2 }]
scanned = Set[row[-1]]
(n - 1).times do
  row << g[row[-1]].select {|i| !scanned.include?(i) }.sort_by {|i| g[i].size }[0]
  scanned << row[-1]
end
puts row * " "

(n - 1).times do
  row = row.map {|i| g[i].select {|j| !scanned.include?(j) }[0] }
  row.each {|i| scanned << i }
  puts row * " "
end

