n = gets.chomp.to_i
nodes = []
n.times do
    tmp = gets.chomp.split.map(&:to_i)
    nodes[tmp[0]] = { id: tmp[0], parent: nil, depth: nil, type: (tmp.size)  < 3 ? "leaf" : "internal node", children: tmp[2, tmp.size - 2] }
end

# rootCand = [*0..(n - 1)]
# nodes.each do |n|
#     next if n[1] == 0
#     rootCand = rootCand - n.drop(2)
# end
# root = rootCand[0]

# ans = []
# nodes.each do |node|
#     id = node[0]
#     parent = nil
#     depth = nil
#     if node.size < 3 then
#         type = "leaf"
#         children = []
#     else
#         type = "internal node"
#         children = node[2, node.size - 2]
#     end
#     if id == root then
#         parent = -1
#         type = "root"
#         depth = 0
#     end
#     ans.push({ id: id, parent: parent, depth: depth, type: type, children: children })
# end

nodes.each do |node|
    next if node[:type] == "leaf"
    node[:children].each do |c|
        nodes[c][:parent] = node[:id]
    end
end

nodes.each do |node|
    if node[:parent] == nil then
        node[:parent] = -1
        node[:type] = "root"
    end
end

nodes.each do |node|
    depth = 0
    parent = node[:parent]
    until parent == -1 do
        parent = nodes[parent][:parent]
        depth += 1
    end
    node[:depth] = depth
end

nodes.each { |node| puts "node #{node[:id]}: parent = #{node[:parent]}, depth = #{node[:depth]}, #{node[:type]}, #{node[:children]}" } 

