class BinaryTree
  attr_accessor :nodes

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

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

  end

  def initialize
    @nodes = []
  end

  def add_node(id, left, right)
    @nodes[id] = Node.new(id) unless @nodes[id]
    if left != -1
      @nodes[left] = Node.new(left) unless @nodes[left]
      @nodes[id].left = @nodes[left]
      @nodes[id].left.parent = @nodes[id]
    end
    if right != -1
      @nodes[right] = Node.new(right) unless @nodes[right]
      @nodes[id].right = @nodes[right]
      @nodes[id].right.parent = @nodes[id]
    end
  end

  def preorder(n)
    return unless n
    print " #{n.id}"
    preorder(n.left)
    preorder(n.right)
  end

  def inorder(n)
    return unless n
    inorder(n.left)
    print " #{n.id}"
    inorder(n.right)
  end

  def postorder(n)
    return unless n
    postorder(n.left)
    postorder(n.right)
    print " #{n.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

root = bt.nodes.select do |n|
  n.parent  == nil
end

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

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

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