def calc_depth nodes, node_id
  parent_node_id = nodes[node_id][0]
  child_node_ids = nodes[node_id][1]
  child_node_id = nodes[node_id][1].length > 0 ? nodes[node_id][1][0] : nil
  sibling_node_id = nodes[node_id][2]

  depth = parent_node_id.nil? ? 0 : nodes[parent_node_id][3] + 1
  nodes[node_id][3] = depth
  child_node_ids.each do |child_node_id|
    nodes[child_node_id][3] = depth + 1
  end

  calc_depth nodes, child_node_id if child_node_id
  calc_depth nodes, sibling_node_id if sibling_node_id
  return
end

def calc_depth_2 nodes
  0.upto(nodes.length - 1) do |i|
    j = i
    d = 0
    while j = nodes[j][0]
      d += 1
    end
    nodes[i][3] = d
  end
end

n = gets.chomp.to_i
nodes = Array.new(n)
while l = gets
  node_id, child_node_num, *child_node_ids = l.chomp.split(' ').map(&:to_i)
  if nodes[node_id]
    nodes[node_id][1] = child_node_ids
  else
    nodes[node_id] = [nil, child_node_ids, nil, nil] # u's parent, u's childs, u's immediate right sibling, u's depth
  end
  0.upto(child_node_num - 1).each do |i|
    child_node_id = child_node_ids[i]
    sibling_node_id = (i + 1 <= child_node_num - 1) ? child_node_ids[i + 1] : nil
    if nodes[child_node_id]
      nodes[child_node_id][0] = node_id
      nodes[child_node_id][2] = sibling_node_id
    else
      nodes[child_node_id] = [node_id, nil, sibling_node_id, nil]
    end
  end
end

root_node_id = nil
0.upto(n - 1) do |i|
  if nodes[i][0].nil?
    root_node_id = i
    break
  end
end
# calc_depth nodes, root_node_id
calc_depth_2 nodes

0.upto(n - 1) do |i|
  node = nodes[i]
  node_type = if node[0].nil?
                'root'
              elsif node[1].empty?
                'leaf'
              else
                'internal node'
              end

  puts "node #{i}: parent = #{node[0] || '-1'}, depth = #{node[3]}, #{node_type}, [#{node[1].join(', ')}]"
end
