$a=[]
class Tree
    attr_accessor :id, :parent, :depth, :children, :type
    def initialize(id, children)
        @id = id
        @parent = -1
        @children = children
        @type = (children == [] ? 'leaf' : 'internal node')
    end

    def print
        puts "node #{id}: parent = #{parent}, depth = #{depth}, #{type}, #{children}"
    end

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

N = gets.to_i

N.times {
    id, d, *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
    }
}
$a.each {|e|
    if e.parent == -1
        e.type = 'root'
        e.depth = 0
        e.setDepth
    end
}
$a.each {|e| e.print}