Tree = {}
Parents = {}

gets.to_i.times do
  i, *c = gets.split(' ').map(&:to_i)
  Tree[i] = c
  c.each{|e| Parents[e] = i}
end

preorder = -> i do
  l = Tree[i][0]
  r = Tree[i][1]
  print " #{i}"
  preorder.(l) if l != -1
  preorder.(r) if r != -1
end

inorder = -> i do
  l = Tree[i][0]
  r = Tree[i][1]
  inorder.(l) if l != -1
  print " #{i}"
  inorder.(r) if r != -1
end

postorder = -> i do
  l = Tree[i][0]
  r = Tree[i][1]
  postorder.(l) if l != -1
  postorder.(r) if r != -1
  print " #{i}"
end

Parents[-1] = nil
root = Tree.keys.reject{|i| Parents.include? i}.first

puts "Preorder"
preorder.(root)
puts "\nInorder"
inorder.(root)
puts "\nPostorder"
postorder.(root)
puts "\n"
