class Node

  attr_reader :id, :parent_id, :depth, :type, :children

  def initialize(id, parent_id, depth, type, children)
    @id = id
    @parent_id = parent_id
    @depth = depth
    @type = type
    @children = children
  end

  def to_s
    "node #{@id}: parent = #{@parent_id}, depth = #{@depth}, #{type}, [#{children.join(', ')}]"
  end

end


n = STDIN.gets.to_i
tree = []
for i in 0..(n - 1)
  as = STDIN.gets.split(' ')
  id = as[0].to_i
  m = as[1].to_i
  parent_node = tree.find { |node|
    node.children.include? id
  }

  parent_id =
    if parent_node.nil? then
      -1
    else
      parent_node.id
    end

  depth =
    if parent_node.nil? then
      0
    else
      parent_node.depth + 1
    end

  type =
    if parent_node.nil? then
      "root"
    elsif m == 0
      "leaf"
    else
      "internal node"
    end

  tree.push(Node.new(id, parent_id, depth, type, as.drop(2).map{|x| x.to_i}))
end

tree.each { |item|
  puts item
}