n = gets.to_i
tree = Struct.new(:parent, :depth, :type, :children)
node = Array.new(n) {tree.new}
n.times do
  ar = gets.split.map(&:to_i)
  node[ar[0]].children = ar[2..-1]
  node[ar[0]].parent = -1
  node[ar[0]].type = "leaf"
end

node.each_with_index do |nd, i|
  nd.children.each {|child| node[child].parent = i}
  nd.type = "internal node" unless nd.children.empty?
end

root_index = 0
node.each_with_index {|nd, i| root_index = i if nd.parent == -1}
node[root_index].type = "root"

search = ->(index, depth) {
  node[index].depth = depth
  children = node[index].children
  return if children.empty?
  children.each {|child| search.(child, depth + 1)}
}
search.(root_index, 0)

node.each_with_index do |nd, i|
  puts "node #{i}: parent = #{nd.parent}, depth = #{nd.depth}, #{nd.type}, #{nd.children.inspect}"
end
