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

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

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

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

  def visit_preorder(&block)
    block.call(self)
    left.visit_preorder(&block) if left
    right.visit_preorder(&block) if right
  end

  def visit_inorder(&block)
    left.visit_inorder(&block) if left
    block.call(self)
    right.visit_inorder(&block) if right
  end

  def visit_postorder(&block)
    left.visit_postorder(&block) if left
    right.visit_postorder(&block) if right
    block.call(self)
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  nodes = Array.new(n) {|id| Node.new(id) }

  n.times do
    id, left_id, right_id = gets.chomp.split.map(&:to_i)
    parent = nodes[id]
    parent.left = nodes[left_id] if left_id != -1
    parent.right = nodes[right_id] if right_id != -1
  end

  root = nodes[0]

  puts 'Preorder'
  root.visit_preorder do |node|
    print " #{node.id}"
  end
  puts

  puts 'Inorder'
  root.visit_inorder do |node|
    print " #{node.id}"
  end
  puts

  puts 'Postorder'
  root.visit_postorder do |node|
    print " #{node.id}"
  end
  puts
end