_, *data = readlines.map(&:chomp)
nodes = data.map {|l| l.split.map(&:to_i)}.sort
x = nodes.reduce({}) do |r, n|
  n[2..-1].each do |c|
    r[c] = n.first
  end
  r
end

def depth(x, n, d=0)
  return d unless x[n]
  depth(x, x[n], d+1)
end

result = nodes.map do |n|
  if x[n.first].nil?
    kind = 'root'
  elsif n[1] == 0
    kind = 'leaf'
  else
    kind = 'internal node'
  end
  parent = x[n.first] || -1
  depth = depth(x, n.first)
  children = n[2..-1].join(', ')
  "node #{n.first}: parent = #{parent}, depth = #{depth}, #{kind}, [#{children}]"
end
puts result
