def Dive(tree, nodei, ans0, ans1, ans2)
   
  ans0 << nodei
  if tree[nodei][1] != -1
    Dive(tree, tree[nodei][1], ans0, ans1, ans2)
  end
  ans1 << nodei
  if tree[nodei][2] != -1
    Dive(tree, tree[nodei][2], ans0, ans1, ans2)
  end
  ans2 << nodei
end
 
tree, ans0, ans1, ans2 = [], [], [], []
 
n = gets.to_i
pretop = Array.new(n, 0) << 1
 
n.times do
  x = gets.split.map(&:to_i)
  tree << x
  pretop[x[1]] += 1
  pretop[x[2]] += 1
end
 
tree = tree.sort_by{|n| n[0]}
 
Dive(tree, pretop.index(0), ans0, ans1, ans2)
puts "Preorder\n #{ans0.join(" ")}\n",
     "Inorder\n #{ans1.join(" ")}\n",
     "Postorder\n #{ans2.join(" ")}"
