class Node
  attr_accessor :key, :left, :right
  def initialize(arr)
    @key = arr[0]
    @left = arr[1]
    @right = arr[2]
  end
  def preorder
    print " ", key
    left.preorder if left != -1
    right.preorder if right != -1
  end
  def inorder
    left.inorder if left != -1
    print " ", key
    right.inorder if right != -1
  end
  def postorder
    left.postorder if left != -1
    right.postorder if right != -1
    print " ", key
  end
end
def to_node(n)
  $tree.each{ |m| n.left = m if n.left == m.key } if n.left != -1 
  $tree.each{ |m| n.right = m if n.right == m.key } if n.right != -1
end
arr = []
$tree = []
n = gets.to_i
n.times do
  node = Node.new(gets.split.map(&:to_i))
  $tree << node
  arr << node.left
  arr << node.right
end
$tree.each{ |n| $root = n unless arr.include?(n.key) }
$tree.each { |n| to_node(n) }
puts "Preorder"
$root.preorder
puts "Inorder"
$root.inorder
puts "Postorder"
$root.postorder