class Node
  def initialize(index, left, right)
    @index = index
    @parent = -1
    @left = left
    @right = right
    @sibling = -1
  end

  attr_accessor :index, :left, :right, :parent, :sibling
end
class BinaryTree
  def initialize(n)
    @node_list = []
    @visited_node = []
    n.times do |i|
      node_list << Node.new(i, nil, nil)
    end
  end

  def create_node(index, left, right)
    node_list[index].left = left
    node_list[index].right = right
    if left != -1
      node_list[left].sibling = right
      node_list[left].parent = index
    end
    if right != -1
      node_list[right].parent = index
    node_list[right].sibling = left
    end
  end

  def preorder_tree_walk(index)
    visited_node << index
    return if node_list[index].left == -1 && node_list[index].right == -1
    if node_list[index].left != -1
      preorder_tree_walk node_list[index].left
    end
    if node_list[index].right != -1
      preorder_tree_walk node_list[index].right
    end
  end

  def inorder_tree_walk(index)
    return if index == -1
    if node_list[index].left != -1
      inorder_tree_walk node_list[index].left
    end
    visited_node << index
    if node_list[index].right != -1
      inorder_tree_walk node_list[index].right
    end
  end

  def postorder_tree_walk(index)
    return if index == -1
    if node_list[index].left != -1
      postorder_tree_walk node_list[index].left
    end
    if node_list[index].right != -1
      postorder_tree_walk node_list[index].right
    end
    visited_node << index
  end

  def search_root
    node_list.find { |node| node.parent == -1 }
  end

  attr_accessor :node_list, :visited_node
end

n = gets.to_i
tree = BinaryTree.new n
n.times do
  input = gets.split(' ').map(&:to_i)
  tree.create_node input[0], input[1], input[2]
end

tree.preorder_tree_walk tree.search_root.index
puts "Preorder\n #{tree.visited_node.join ' '}"
tree.visited_node = []
tree.inorder_tree_walk tree.search_root.index
puts "Inorder\n #{tree.visited_node.join ' '}"
tree.visited_node = []
tree.postorder_tree_walk tree.search_root.index
puts "Postorder\n #{tree.visited_node.join ' '}"

