class Node
  attr_reader :id, :left, :right
  attr_accessor :parent

  def initialize(id)
    @id = id
    @parent = nil
    @left = nil
    @right = nil
  end

  def left=(child)
    child.parent = self
    @left = child
  end

  def right=(child)
    child.parent = self
    @right = child
  end

  def sibling
    return nil unless parent

    [parent.left, parent.right].compact.find {|node| node.id != id }
  end

  def degree
    [left, right].compact.size
  end

  def depth
    ret = 0
    p = parent
    while p
      ret += 1
      p = p.parent
    end
    ret
  end

  def height
    left_height = left ? left.height + 1 : 0
    right_height = right ? right.height + 1 : 0
    [left_height, right_height].max
  end

  def type
    if parent.nil?
      'root'
    elsif left || right
      'internal node'
    else
      'leaf'
    end
  end

  def to_s
    parent_id = parent ? parent.id : -1
    sibling_id = sibling ? sibling.id : -1
    "node #{id}: parent = #{parent_id}, sibling = #{sibling_id}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  nodes = Array.new(n) {|id| Node.new(id) }

  n.times do
    id, left_id, right_id = gets.chomp.split.map(&:to_i)
    parent = nodes[id]
    parent.left = nodes[left_id] if left_id != -1
    parent.right = nodes[right_id] if right_id != -1
  end

  nodes.each do |node|
    puts node
  end
end