$a=[]
rootID=0
class Tree
    attr_accessor :id, :parent, :sibling, :degree, :depth, :height, :children, :type, :inPrinted
    def initialize(id, children, degree)
        @id = id
        @parent = -1
        @sibling = -1
        @degree = degree
        @height = 0
        @children = children
        @type = (children == [-1, -1] ? 'leaf' : 'internal node')
        @inrinted= false
    end

    def setDepth
        children.each {|c|
            unless c == -1
                $a[c].depth = depth + 1
                $a[c].setDepth
            end
        }
    end

    def setHeight
        unless parent == -1
            $a[parent].height = height + 1 if $a[parent].height < height + 1
            $a[parent].setHeight
        end
    end

    def data
        puts "node #{id}: parent = #{parent}, sibling = #{sibling}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
    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]].preorder unless children[0] == -1
        $a[children[1]].preorder unless children[1] == -1
        print ' ', id
    end
end

N = gets.to_i

N.times {
    id, *children = gets.split.map(&:to_i)
    degree = 2
    children.each {|e| degree -= 1 if e == -1}
    $a << Tree.new(id, children, degree)
}
$a.sort_by! {|e| e.id}
$a.each {|ele|
    ele.children.each {|e|
        unless e == -1
            $a[e].parent = ele.id
            $a[e].sibling = (e == ele.children[0] ? ele.children[1] : ele.children[0])
        end
    }
}
$a.each {|e|
    if e.parent == -1
        e.type = 'root'
        e.depth = 0
        e.setDepth
        rootID = e.id
    end

    e.setHeight if e.type == 'leaf'
}
$a.each {|e| e.data}
puts 'Preorder'
$a[rootID].preorder
puts '', 'Inorder'
$a[rootID].inorder
puts '', 'Postorder'
$a[rootID].postorder
puts