# Node
class Node
  attr_accessor :id, :parent, :children

  def initialize(id, parent = nil, children = [])
    @id, @parent, @children = id, parent, children
  end
end

# RootedTree
class RootedTree
  attr_accessor :nodes

  def initialize(data)
    @nodes = data.map do |id, foo|
      Node.new(id, foo[:parent], foo[:children])
    end
  end

  def depth(id)
    node = @nodes.find { |node| node.id == id }
    unless node.parent.nil?
      return depth(node.parent) + 1
    else
      return 0
    end
  end

  def root?(id)
    node = @nodes.find { |node| node.id == id }
    node.parent.nil?
  end

  def leaf?(id)
    node = @nodes.find { |node| node.id == id }
    node.children.empty?
  end
end

data = {}
children = {}

n = gets.chop.to_i

n.times do
  id, k, *c = gets.chop.split.map(&:to_i)
  data[id] = {}
  data[id][:children] = c
  c.each do |child|
    children[child] = id
  end
end

data = Hash[data.sort]

data.each do |key, value|
  value[:parent] = (!children[key].nil?) ? children[key] : nil
end

t = RootedTree.new(data)

t.nodes.each do |node|
  puts "node #{node.id}: parent = " + ((!node.parent.nil?) ? node.parent : -1).to_s + ", depth = " + t.depth(node.id).to_s + ", " + (t.root?(node.id) ? "root" : t.leaf?(node.id) ? "leaf" : "internal node").to_s + ", #{node.children}"
end