class Node
  attr_accessor :id, :left, :right, :parent
  def initialize(input)
    @id, @left, @right = input
    @parent = nil
  end
end

class Binary_tree
  def initialize(n, inputs)
    #nodesを生成
    @nodes = inputs.inject({}) do |memo, input|
      memo[input[0]] = Node.new(input)
      memo
    end

    #left, rightにポインタを代入
    @nodes.each do |key, node|
      @nodes[key].left = (@nodes[key].left != -1 ? @nodes[@nodes[key].left] : nil)
      @nodes[key].right = (@nodes[key].left != -1 ? @nodes[@nodes[key].right] : nil)
    end

    @root = get_root()
  end

  def get_root
    @nodes.each do |key, node|
      if @nodes[key].left
        @nodes[key].left.parent = @nodes[key]
      end

      if @nodes[key].right
        @nodes[key].right.parent = @nodes[key]
      end
    end

    @nodes.each do |key, node|
      if !node.parent
        return key
      end
    end
  end


  def preorder(node)
    if !node
      return
    end
    print " %d" % [node.id.to_s]
    preorder(node.left)
    preorder(node.right)
  end

  def inorder(node)
    if !node
      return
    end
    inorder(node.left)
    print " %d" % [node.id.to_s]
    inorder(node.right)
  end

  def postorder(node)
    if !node
      return
    end
    postorder(node.left)
    postorder(node.right)
    print " %d" % [node.id.to_s]
  end

  def run
    #p @nodes
    puts "Preorder"
    preorder(@nodes[@root])
    print "\n"

    puts "Inorder"
    inorder(@nodes[@root])
    print "\n"

    puts "Postorder"
    postorder(@nodes[@root])
    print "\n"
  end
end

n = gets.to_i
inputs = Array.new(n){gets.split.map(&:to_i)}
Binary_tree.new(n, inputs).run
