class Tree
  attr_accessor :id, :parent, :left, :right, :depth, :children, :type
end

N = gets.chomp.to_i
@trees = []

def calc_depth(tree)
  if tree.parent.nil?
    tree.depth = 0
  else
    if @trees[tree.parent].depth.nil?
      calc_depth(@trees[tree.parent])
    end
    tree.depth = @trees[tree.parent].depth + 1
  end
end

def decide_type(tree)
  if tree.parent.nil?
    "root"
  elsif tree.children.size == 0
    "leaf"
  else
    "internal node"
  end
end

def out_format(tree)
  tree.type = decide_type(tree)
  tree.parent = -1 if tree.parent.nil?
  str_children = "[#{tree.children * ", "}]"
  "node #{tree.id}: parent = #{tree.parent}, depth = #{tree.depth}, #{tree.type}, #{str_children}"
end

N.times do
  @trees << Tree.new
end

N.times do
  tmp = gets.chomp.split(" ").map(&:to_i)
  id = tmp.shift
  @trees[id].id = id
  child_num = tmp.shift
  @trees[id].children = tmp

  l = nil
  child_num.times do |j|
    if j == 0
      @trees[id].left = tmp[j]
    else
      @trees[l].right = tmp[j]
    end
    l = tmp[j]
    @trees[tmp[j]].parent = id
  end
end

@trees.each { |e| calc_depth(e) }
@trees.sort!{ |x, y| x.id <=> y.id }
@trees.each { |e| puts out_format(e) }

