class BinaryTree
  attr_accessor :nodes

  class Node
    attr_accessor :id, :left, :right

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

  end

  def initialize
    @nodes = {}
    @nodes[-1] = Node.new(-1)
  end

  def add_node(id, left, right)
    @nodes[id] = Node.new(id) unless @nodes[id]
    @nodes[left] = Node.new(left) unless @nodes[left]
    @nodes[right] = Node.new(right) unless @nodes[right]
    @nodes[id].left = @nodes[left]
    @nodes[id].right = @nodes[right]
  end

  def preorder(id)
    return if id == -1
    print " #{id}"
    preorder(@nodes[id].left.id)
    preorder(@nodes[id].right.id)
  end

  def inorder(id)
    return if id == -1
    inorder(@nodes[id].left.id)
    print " #{id}"
    inorder(@nodes[id].right.id)
  end

  def postorder(id)
    return if id == -1
    postorder(@nodes[id].left.id)
    postorder(@nodes[id].right.id)
    print " #{id}"
  end

end

n = gets.to_i
bt = BinaryTree.new
n.times do |i|
  id, left, right = gets.split.map { |i| i.to_i }
  bt.add_node(id, left, right)
end

puts "Preorder"
bt.preorder(0)
print "\n"

puts "Inorder"
bt.inorder(0)
print "\n"

puts "Postorder"
bt.postorder(0)
print "\n"