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

  attr_accessor :id, :parent, :left, :right
end

def find_root(node_map)
  node_map.values.each do |node|
    return node if node.parent == -1
  end
end

def walk_inorder(node, node_map, container)
  if (node.left != -1) then
    walk_inorder(node_map[node.left], node_map, container)
  end
  container << node.id
  if (node.right != -1) then
    walk_inorder(node_map[node.right], node_map, container)
  end
end

def walk_preorder(node, node_map, container)
  container << node.id
  if (node.left != -1) then
    walk_preorder(node_map[node.left], node_map, container)
  end
  if (node.right != -1) then
    walk_preorder(node_map[node.right], node_map, container)
  end
end

def walk_postorder(node, node_map, container)
  if (node.left != -1) then
    walk_postorder(node_map[node.left], node_map, container)
  end
  if (node.right != -1) then
    walk_postorder(node_map[node.right], node_map, container)
  end
  container << node.id
end

n = gets.chomp.to_i
node_map = {}

(n).times do |i|
  node_map[i] = Node.new(i, -1, -1)
end

(n).times do
  inputs = gets.chomp.split.map(&:to_i)
  node_map[inputs[0]].left = inputs[1]
  node_map[inputs[0]].right = inputs[2]
  inputs[1..2].each do |child|
    if child != -1 then
      node_map[child].parent = inputs[0]
    end
  end
end

root_node = find_root(node_map)

puts "Preorder"
container1 = []
walk_preorder(root_node, node_map, container1)
puts container1.join(' ')
puts "Inorder"
container1 = []
walk_inorder(root_node, node_map, container1)
puts container1.join(' ')
puts "Postorder"
container1 = []
walk_postorder(root_node, node_map, container1)
puts container1.join(' ')