$arr=Array.new
root=0
class Tree
  attr_accessor :id,:children,:parent
  def initialize(id,children)
    @id=id
    @parent=-1
    @children=children
  end

  def preParse
    print " #{id}"
    $arr[children[0]].preParse unless children[0]==-1
    $arr[children[1]].preParse unless children[1]==-1
  end
  def inParse
    $arr[children[0]].inParse unless children[0]==-1
    print " #{id}"
    $arr[children[1]].inParse unless children[1]==-1
  end
  def postParse
    $arr[children[0]].postParse unless children[0]==-1
    $arr[children[1]].postParse unless children[1]==-1
    print " #{id}"
  end
end
n=gets.to_i
n.times do
  num,*children=gets.split.map(&:to_i)
  $arr << Tree.new(num,children)
end
$arr.sort_by! do |e|
  e.id
end
$arr.each do |ele|
  ele.children.each do |e|
    $arr[e].parent=ele.id unless e==-1
  end
end
$arr.each do |e|
  if e.parent==-1
    root=e.id
  end
end
puts "Preorder"
$arr[root].preParse
print "\n"
puts "Inorder"
$arr[root].inParse
print "\n"
puts "Postorder"
$arr[root].postParse
print "\n"