class Node
  attr_accessor :id, :left, :right, :parent, :sibling
  def initialize(id, left=nil, right=nil)
    @id, @left, @right = id, left, right
    @sibling, @parent = nil, nil
  end

  def height
    return -1 if @id == -1
    return @left.height < @right.height ? @right.height+1: @left.height+1
  end

  def depth(root)
    return 0 if @id==root.id
    return @parent.depth(root) + 1
  end

  def type
    if @parent.id == -1
      return "root"
    elsif @left.id==-1 && @right.id==-1
      return "leaf"
    else
      return "internal node"
    end
  end

  def degree
    if @left.id>=0 && @right.id>=0
      return 2
    elsif @left.id==-1 && @right.id==-1
      return 0
    else
      return 1
    end
  end
end

n = gets.to_i
nodes = []
(0..n-1).each do |i|
  id, l, r = gets.split.map(&:to_i)
  nodes[id] = Node.new(id, l, r)
end

nodes.each do |i|
  i.left = i.left==-1 ? Node.new(-1):nodes[i.left]
  i.right = i.right==-1 ? Node.new(-1):nodes[i.right]
  i.left.sibling, i.right.sibling = i.right, i.left
  i.left.parent = i.right.parent = i
end

root = nil
nodes.each do |i|
  if i.parent == nil
    root = i
    root.sibling, root.parent = Node.new(-1), Node.new(-1)
  end
end

(0..nodes.size-1).each do |i|
  c = nodes[i]
  puts "node #{i}: parent = #{c.parent.id}, sibling = #{c.sibling.id}, degree = #{c.degree}, depth = #{c.depth(root)}, height = #{c.height}, #{c.type}"
end
