$a=[]
rootID=0
class Tree
    attr_accessor :id, :parent, :children
    def initialize(id, children)
        @id = id
        @parent = -1
        @children = children
    end

    def preorder
        print ' ', id
        $a[children[0]].preorder unless children[0] == -1
        $a[children[1]].preorder unless children[1] == -1
    end

    def inorder
        $a[children[0]].inorder unless children[0] == -1
        print ' ', id
        $a[children[1]].inorder unless children[1] == -1
    end

    def postorder
        $a[children[0]].postorder unless children[0] == -1
        $a[children[1]].postorder unless children[1] == -1
        print ' ', id
    end
end

N = gets.to_i

N.times {
    id, *children = gets.split.map(&:to_i)
    $a << Tree.new(id, children)
}
$a.sort_by! {|e| e.id}
$a.each {|ele|
    ele.children.each {|e| $a[e].parent = ele.id unless e == -1}
}
$a.each {|e| rootID = e.id if e.parent == -1}

puts 'Preorder'
$a[rootID].preorder
puts '', 'Inorder'
$a[rootID].inorder
puts '', 'Postorder'
$a[rootID].postorder
puts