n = gets.to_i
@bt = Hash.new
hasNode = Array.new n, false
n.times do
  node, left, right = readline.split(" ").map(&:to_i)
  @bt[node] = {left: left, right: right}
  hasNode[left] = true unless left == -1
  hasNode[right] = true unless right == -1
end

top = hasNode.index false

def preorder i
  l = @bt[i][:left] == -1 ? [] : preorder(@bt[i][:left])
  r = @bt[i][:right] == -1 ? [] : preorder(@bt[i][:right])
  return [i] + l + r
end

def inorder i
  l = @bt[i][:left] == -1 ? [] : inorder(@bt[i][:left])
  r = @bt[i][:right] == -1 ? [] : inorder(@bt[i][:right])
  return l + [i] + r
end

def postorder i
  l = @bt[i][:left] == -1 ? [] : postorder(@bt[i][:left])
  r = @bt[i][:right] == -1 ? [] : postorder(@bt[i][:right])
  return l + r + [i]
end

puts "Preorder"
puts " " + preorder(top).map(&:to_s).join(" ")
puts "Inorder"
puts " " + inorder(top).map(&:to_s).join(" ")
puts "Postorder"
puts " " + postorder(top).map(&:to_s).join(" ")
