class Vertex
  include Comparable
  attr_reader :parent, :id, :children
  def initialize(n, degree)
    @id = n
    @parent = -1
    @degree = degree
    @type = "root"
  end
  
  def set_child(*children)
    if @degree != 0
      @children = children
    else
      @children = []
    end
  end
  
  def to_s
    return "node #{@id}: parent = #{@parent == -1 ? @parent: @parent.id}, depth = #{depth}, #{@type}, [#{@children.join(", ")}]"
  end
  
  def depth
    if @parent != -1
      return @parent.depth + 1
    else
      return 0
    end
  end
  
  def set_parent(parent)
    @parent = parent
    if @degree == 0
      @type = "leaf"
    else
      @type = "internal node"
    end
  end
  
  def <=>(other)
    @id <=> other.id
  end
end
def main
  arr = []
  gets.to_i.times do
    str = gets.split(" ").map(&:to_i)
    arr << Vertex.new(*str[0, 2])
    arr.last.set_child(*str[2..-1])
  end
  arr.sort!
  arr.each{|item|
    item.children.each{|child|
      arr[child].set_parent(item)
      }
    }
  puts arr
end
def test
  arr = []
  file = open("tree1.txt")
  file.gets.to_i.times do
    str = file.gets.split(" ").map(&:to_i)
    arr << Vertex.new(*str[0, 2])
    arr.last.set_child(*str[2..-1])
  end
  arr.sort!
  arr.each{|item|
    item.children.each{|child|
      arr[child].set_parent(item)
      }
    }
  puts arr
end
main