#tree_walk
class Node
  attr_accessor :myname,:parent,:left,:right,:depth

  def initialize(n)
    @myname = n
    @parent = -1
    @left   = nil
    @right  = nil
  end

  def add_left(child)
      self.left    = child
      child.parent = self
  end

  def add_right(child)
      self.right    = child
      child.parent = self
  end

  def preorder
    printf(" %d",self.myname)
    if(left != nil)
      left.preorder
    end
    if(right!= nil)
      right.preorder
    end
  end

  def inorder
    if(left != nil)
      left.inorder
    end
    printf(" %d",self.myname)
    if(right!= nil)
      right.inorder
    end
  end

  def postorder
    if(left != nil)
      left.postorder
    end
    if(right!= nil)
      right.postorder
    end
    printf(" %d",self.myname)
  end

end


n = STDIN.gets.split[0].to_i
tree=Array.new(n){|i| Node.new(i)}

0.upto(n-1){|i|
  s = STDIN.gets.split
  id= s[0].to_i
  l = s[1].to_i
  r = s[2].to_i

#  printf("%d %d %d:\n",id,l,r)
  if(l != -1)
    tree[id].add_left(tree[l])
  end
  if(r != -1)
    tree[id].add_right(tree[r])
  end
}


def findroot(tree,n)
  0.upto(n-1){|i|
    if tree[i].parent == -1 
      return i
    end
  }
end 


rt = findroot(tree,n)
puts "Preorder"
tree[rt].preorder
printf("\n")
puts "Inorder"
tree[rt].inorder
printf("\n")
puts "Postorder"
tree[rt].postorder
printf("\n")