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

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