class Node
  attr_accessor :id, :parent, :left, :right

  def initialize(id)
    @id = id
    @parent = -1
    @left = nil
    @right = nil
  end

  def add_left(left)
    @left = left
    @left.parent = self
  end

  def add_right(right)
    @right = right
    @right.parent = self
  end

end

class BinaryTree
  attr_accessor :root, :list

  def initialize(root)
    @root = root
  end

  def pre
    # 行きがけ順探索(左上から順に)
    @list = []
    traverse(@root, :pre)
    @list
  end

  def in
    # 通りがけ順探索
    @list = []
    traverse(@root, :in)
    @list
  end

  def post
    # 帰りがけ順探索(左下から順に)
    @list = []
    traverse(@root, :post)
    @list
  end

  private
  def traverse(node, type)
    @list << node.id if type == :pre
    traverse(node.left, type) if node.left
    @list << node.id if type == :in
    traverse(node.right, type) if node.right
    @list << node.id if type == :post
  end
end

n = gets.to_i
tree = Array.new(n){ | i | Node.new(i) }
n.times do
  id, l, r = gets.split.map(&:to_i)
  tree[id].add_left(tree[l])  if l != -1
  tree[id].add_right(tree[r]) if r != -1
end

root = nil
tree.each{ | n | root = n if n.parent == -1 }

bt = BinaryTree.new(root)
puts 'Preorder'
puts " #{bt.pre.join(' ')}"
puts 'Inorder'
puts " #{bt.in.join(' ')}"
puts 'Postorder'
puts " #{bt.post.join(' ')}"
