def print_by_preorder nodes, node_id, res
  left_id = nodes[node_id][0]
  right_id = nodes[node_id][1]
  res << node_id
  print_by_preorder nodes, left_id, res if left_id != -1
  print_by_preorder nodes, right_id, res if right_id != -1
  return res
end

def print_by_inorder nodes, node_id, res
  left_id = nodes[node_id][0]
  right_id = nodes[node_id][1]
  print_by_inorder nodes, left_id, res if left_id != -1
  res << node_id
  print_by_inorder nodes, right_id, res if right_id != -1
  return res
end

def print_by_postorder nodes, node_id, res
  left_id = nodes[node_id][0]
  right_id = nodes[node_id][1]
  print_by_postorder nodes, left_id, res if left_id != -1
  print_by_postorder nodes, right_id, res if right_id != -1
  res << node_id
  return res
end

n = gets.chomp.to_i
nodes = Array(n)
not_roof_ids = []
while l = gets
  node_id, left_id, right_id = l.chomp.split(' ').map(&:to_i)
  nodes[node_id] = [left_id, right_id]
  not_roof_ids << left_id
  not_roof_ids << right_id
end
root_node_id = nil
nodes.each_with_index do |n, i|
  unless not_roof_ids.include?(i)
    root_node_id = i
    break
  end
end

puts 'Preorder'
res = print_by_preorder nodes, root_node_id, []
puts ' ' + res.join(' ')
puts 'Inorder'
res = print_by_inorder nodes, root_node_id, []
puts ' ' + res.join(' ')
puts 'Postorder'
res = print_by_postorder nodes, root_node_id, []
puts ' ' + res.join(' ')
