n = gets.chomp.to_i
nodes = []
n.times do
    id, left, right = gets.chomp.split.map(&:to_i)
    nodes[id] = { id: id, left: left, right: right, parent: nil, sibling: nil, degree: nil, depth: nil, height: nil, type: nil }
end

nodes.each do |node|
    children = [node[:left], node[:right]]
    children.each do |c|
        if c != -1 then
            nodes[c][:parent] = node[:id]
        end
    end
    if children.count(-1) == 2 then
        node[:type] = "leaf"
        node[:degree] = 0
    elsif children.count(-1) == 1 then
        node[:type] = "internal node"
        node[:degree] = 1
    else
        node[:type] = "internal node"
        node[:degree] = 2
    end
end

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

nodes.each do |node|
    next if node[:sibling] != nil
    node[:sibling] = -1
    nodes.each do |anotherNode|
        next if node[:id] == anotherNode[:id]
        if node[:parent] == anotherNode[:parent] then
            node[:sibling] = anotherNode[:id]
            anotherNode[:sibling] = node[:id]
        end
    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

def getHeight(nodes, id, height)
    height += 1
    leftHeight = height
    rightHeight = height
    leftHeight = getHeight(nodes, nodes[id][:left], leftHeight) unless nodes[id][:left] == -1
    rightHeight = getHeight(nodes, nodes[id][:right], rightHeight) unless nodes[id][:right] == -1
    return [leftHeight, rightHeight].max
end

nodes.each do |node|
    height = -1
    height = getHeight(nodes, node[:id], height)
    node[:height] = height
end

# nodes.each { |node| p node }
nodes.each { |node| puts "node #{node[:id]}: parent = #{node[:parent]}, sibling = #{node[:sibling]}, degree = #{node[:degree]}, depth = #{node[:depth]}, height = #{node[:height]}, #{node[:type]}" }
