def set_depth nodes, node_id, depth
  nodes[node_id][3] = depth
  set_depth nodes, nodes[node_id][1][0], depth + 1 if nodes[node_id][1][0] != -1
  set_depth nodes, nodes[node_id][1][1], depth + 1 if nodes[node_id][1][1] != -1
end

def set_height nodes, node_id, height
  nodes[node_id][4] = height if !nodes[node_id][4] || nodes[node_id][4] < height
  set_height nodes, nodes[node_id][0], height + 1 if nodes[node_id][0] != -1
end

n = gets.chomp.to_i
nodes = Array.new(n)
while l = gets
  node_id, *child_node_ids = l.chomp.split(' ').map(&:to_i)
  if nodes[node_id]
    nodes[node_id][1] = child_node_ids
  else
    nodes[node_id] = [-1, child_node_ids, -1, nil, nil] # u's parent, u's children, u's sibling, u's depth, u's height
  end
  child_node_ids.each_with_index do |child_node_id, i|
    if child_node_id != -1
       sibling_node_id = (i == 0) ? child_node_ids[1] : child_node_ids[0]
       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, [], sibling_node_id, nil, nil]
       end
    end
  end
end

root_node_id = nil
nodes.each_with_index do |node, i|
  if node[0] == -1
    root_node_id = i
    break
  end
end
set_depth nodes, root_node_id, 0
nodes.each_with_index do |node, i|
  degree = node[1].count{|c| c != -1}
  set_height nodes, i, 0 if degree == 0
end

nodes.each_with_index do |node, i|
  degree = node[1].count{|c| c != -1}
  node_type = if node[0] == -1
                'root'
              elsif degree == 0
                'leaf'
              else
                'internal node'
              end
  puts "node #{i}: parent = #{node[0]}, sibling = #{node[2]}, degree = #{degree}, depth = #{node[3]}, height = #{node[4]}, #{node_type}"
end
