n = gets.to_i

# クラスってかこの程度なら構造体で充分なんだがな!!!!!!!!!!!!!!!!!!!!!!!!!!!
class Tree
  attr_accessor :id, :parent, :depth, :tree_type, :childs
  def initialize
    @childs = []
    @parent = -1
    @depth = 0
  end
end
trees = {}
# 数がわかっているので初期化
n.times do |i|
  tree = Tree.new()
  tree.id = i
  trees[i] = tree
end

# 単にdepthを深くしていくやつ
def rec(par, childs, target)
  if childs.size > 0
    childs.each do |c|
      target[c].parent = par
      target[c].depth = target[par].depth + 1
      rec(c, target[c].childs, target)
    end
  end
end

n.times do
  t = gets.chomp.split.map(&:to_i)
  myid = t[0]
  mychilds = []
  if t[1] > 0
    mychilds = t[2, t[1]]
  end
  trees[myid].childs = mychilds
  # 再帰的にdepthとparentを更新
  rec(myid, mychilds, trees)
end

# root、internal node、leaf
trees.each do |t|
  if t[1].parent == -1
    t[1].tree_type = "root"
  elsif t[1].childs.size.zero?
    t[1].tree_type = "leaf"
  else
    t[1].tree_type = "internal node"
  end
end

# 出力
n.times do |i|
  puts "node #{trees[i].id}: parent = #{trees[i].parent}, depth = #{trees[i].depth}, #{trees[i].tree_type}, [#{trees[i].childs.map(&:to_s).join(', ')}]"
end
