class Node
  def initialize(node)
    @node = node
    @parent = nil
    @children = []
    @depth = 0
  end

  def who_am_i
    if @parent == -1
      'root'
    elsif @children.empty?
      'leaf'
    else
      'internal_node'
    end
  end

  def to_s
    "node #{node}: parent = #{parent}, depth = #{depth}, #{who_am_i}, #{children}"
  end

  attr_accessor :node, :parent, :children, :depth
end

class RootedTree
  def initialize(k)
    @node_list = []
    k.times do |i|
      @node_list << Node.new(i)
    end
  end

  def create_node(index, children)
    @node_list[index].children = children
    unless children.empty?
      children.each do |value|
        @node_list[value].parent = index
      end
    end
  end

  def eval_depth_of(index, target_node_index)
    return if @node_list[index].parent == -1
    @node_list[target_node_index].depth += 1
    eval_depth_of @node_list[index].parent, target_node_index
  end

  def search_root_node
    @node_list.each do |node|
      node.parent = -1 if node.parent.nil?
    end
  end

  attr_reader :node_list
end

n = gets.to_i
tree = RootedTree.new n
n.times do
  input = gets.split(' ').map(&:to_i)
  if !input[1].zero?
    children = input[1..-1]
  else
    children = []
  end
  tree.create_node input[0], children
end
tree.search_root_node

tree.node_list.each do |node|
  tree.eval_depth_of node.node, node.node
end

tree.node_list.each do |node|
  puts node.to_s
end


