class BinTree
  attr_accessor :node
  def initialize(n)
    @node = Array.new(n){Node.new()}
  end
  def preorder(n=root())
    str = ""
    return str if n < 0
    #root
    str << sprintf(" %s", n)
    #left
    str << preorder(node[n].left)
    #right
    str << preorder(node[n].right)
    return str
  end
  def inorder(n=root())
    str = ""
    return str if n < 0
    #left
    str << inorder(node[n].left)
    #root
    str << sprintf(" %s", n)
    #right
    str << inorder(node[n].right)
    return str
  end
  def postorder(n=root())
    str = ""
    return str if n < 0
    #left
    str << postorder(node[n].left)
    #right
    str << postorder(node[n].right)
    str << sprintf(" %s", n)
  end
  def root
    #find root
    r = 0
    node.size.times {|i|
      if node[i].parent == -1 then
        r = i
        break
      end
    }
    return r
  end
  def add(i, l, r)
    node[i].left = l
    node[i].right = r
    node[l].parent = i unless l == -1
    node[r].parent = i unless r == -1
  end
end

class Node
  attr_accessor :parent, :left, :right
  def initialize
    @parent = -1
    @left = -1
    @right = -1
  end
end



n = gets.to_i
tree = BinTree.new(n)

n.times{
  i, l, r = gets.split.map(&:to_i)
  tree.add(i, l, r)
}

puts "Preorder"
puts tree.preorder()
puts "Inorder"
puts tree.inorder()
puts "Postorder"
puts tree.postorder()