class Tree
  class Node
    attr_accessor :id, :parent, :depth, :type, :children
    def initialize(id,parent,depth,type,children)
      @id = id
      @parent = parent
      @depth = depth
      @type = type
      @children = children
    end
  end
  
  attr_accessor :nodes
  def initialize
    @nodes = []
    @parents = {}
  end

  def update(node)
    if !node
      return
    end
    node.parent = @parents[node.id]
    node.depth = @nodes[node.parent].depth + 1
    if node.children == []
      node.type = "leaf"
    else
      node.type = "internal node"
    end
    node.children.each do |c|
      update(@nodes[c])
    end
  end

  def addNode(id,children)
    if !@parents[id]
      type = "root"
      parent = -1
      depth = 0
    else
      parent = @parents[id]
      depth = @nodes[parent].depth + 1
      if children == []
        type = "leaf"
      else
        type = "internal node"
      end
    end
    nodes[id] = Node.new(id,parent,depth,type,children)
    
    children.each do |c|
      @parents[c] = id
      update(@nodes[c])
    end
  end
end

t = Tree.new
n = gets.to_i
(n).times do
  id,_,*children = gets.split.map(&:to_i)
  t.addNode(id,children)
end

(n).times do |i|
  node = t.nodes[i]
  printf("node %d: parent = %d, depth = %d, %s, [%s]\n", node.id, node.parent, node.depth, node.type, node.children.join(", "))
end
