Node = Struct.new(:id, :c, :parent, :depth, :type)

nodes = $<.gets.to_i.times.map do
  id, k, *c = $<.gets.split.map(&:to_i)
  Node.new(id, c)
end.sort_by(&:id)

h = nodes.map {|n| [n.id, n]}.to_h
nodes.each {|n| n.c.each {|c| h[c].parent = n.id} }

root = nodes.find {|n| !n.parent}
root.parent = -1

search = ->(node, depth) {
  node.depth = depth
  if node.c.empty?
    node.type = "leaf"
  else
    node.type = "internal node"
    node.c.each {|c| search.(h[c], depth + 1)}
  end
}
search.(root, 0)
root.type = "root"

puts nodes.map {|n| "node #{n.id}: parent = #{n.parent}, depth = #{n.depth}, #{n.type}, #{n.c}"}
