class Node
  attr_reader :id
  attr_accessor :parent

  def initialize(id)
    @id = id
    @children = []
  end

  def <<(child)
    child.parent = self
    @children << child
  end

  def depth
    ret = 0
    p = self.parent
    while p
      ret += 1
      p = p.parent
    end
    ret
  end

  def type
    if parent.nil?
      'root'
    elsif @children.any?
      'internal node'
    else
      'leaf'
    end
  end

  def to_s
    "node #{id}: parent = #{parent ? parent.id : -1}, depth = #{depth}, #{type}, [#{child_ids.join(', ')}]"
  end

  private

  def child_ids
    @children.map(&:id)
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  nodes = Array.new(n) {|id| Node.new(id) }

  n.times do
    id, _, *child_ids = gets.chomp.split.map(&:to_i)

    parent = nodes[id]

    child_ids.each do |child_id|
      child = nodes[child_id]
      parent << child
    end
  end

  nodes.each do |node|
    puts node
  end
end