class Node

  attr_accessor:id, :parent, :left, :right, :depth, :height

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

  def depth
    if @parent.nil?
      0
    else
      @parent.depth + 1
    end
  end

  def type
    if @parent == nil
      "root"
    elsif @child_left.nil?
      "leaf"
    else
      "internal node"
    end
  end

  def to_s
    parent_id =
      if @parent.nil?
        -1
      else
        @parent.id
      end

    degree = 0
    if @left != nil
      degree = degree + 1
    end
    if @right != nil
      degree = degree + 1
    end

    type =
      if @parent.nil?
        "root"
      elsif @left.nil? && @right.nil?
        "leaf"
      else
        "internal node"
      end

    "node #{@id}: parent = #{parent_id}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
  end

  def children_to_s
    ss = []
    if @child_left.nil?
      ss
    else
      a = @child_left
      while a != nil
        ss.push(a.id.to_s)
        a = a.right_sibling
      end
      ss
    end
  end
end

n = STDIN.gets.to_i

tree = []
for i in 0..(n - 1)
  as = STDIN.gets.split(' ')
  id = as[0].to_i
  left_id = as[1].to_i
  right_id = as[2].to_i

  node = tree[id]
  if node.nil?
    node = Node.new(id)
    tree[id] = node
  end

  if left_id != -1
    left = tree[left_id]
    if left.nil?
      left = Node.new(left_id)
      left.parent = node
      tree[left_id] = left
    end
    node.left = left
  end

  if right_id != -1
    right = tree[right_id]
    if right.nil?
      right = Node.new(right_id)
      right.parent = node
      tree[right_id] = right
    end
    node.right = right
  end

  if left_id != -1 && right_id != -1
    a = node
    while a != nil
      a.height = a.height + 1
      a = a.parent
    end
  end
end

for i in 0..(n-1)
  puts tree[i].to_s
end