class Node
  attr_accessor :left, :right, :parent, :height, :depth, :type, :sibling, :degree
  def initialize(ary)
    @left, @right = ary
    @parent = -1
    @height = 0
    @depth = 0
    @type = ""
    @sibling = -1
    @degree = 0
  end
end


#入力
n = gets.to_i
inputs = Array.new(n){gets.split.map(&:to_i)}

# nodesをidをキーとしたハッシュで持つ。
$nodes = inputs.inject({}){|memo, input| memo[input.shift] = Node.new(input);memo}

#parent, sibling, degreeをセット
def set_parent_and_sibling_and_degree
  $nodes.each_key do |key|
    if $nodes[key].left != -1
      $nodes[$nodes[key].left].parent = key.to_i
      $nodes[key].degree += 1
    end

    if $nodes[key].right != -1
      $nodes[$nodes[key].right].parent = key.to_i
      $nodes[key].degree += 1
    end

    if $nodes[key].left!=-1 && $nodes[key].right != -1
      $nodes[$nodes[key].left].sibling = $nodes[key].right
      $nodes[$nodes[key].right].sibling = $nodes[key].left
    end
  end
end

#rootをゲット
def root
  $nodes.each_key do |key|
    if $nodes[key].parent == -1
      return $nodes[key]
    end
  end
end

#heightをセット
def set_height(node)
  h1, h2 = 0, 0

  if node.left!=-1
    h1 = set_height($nodes[node.left]) + 1
  end

  if node.right!=-1
    h2 = set_height($nodes[node.right]) + 1
  end

  return node.height = [h1, h2].max
end

#depthをセット
def set_depth(node, cnt)
  node.depth = cnt
  if node.left!=-1
    set_depth($nodes[node.left], cnt+1)
  end
  if node.right!=-1
   set_depth($nodes[node.right], cnt+1)
  end
end

#typeをセット
def set_type
  $nodes.each_key do |key|
    if $nodes[key].parent == -1
      $nodes[key].type = "root"
    elsif $nodes[key].left == -1 && $nodes[key].right == -1
      $nodes[key].type = "leaf"
    else
      $nodes[key].type = "internal node"
    end
  end
end

set_parent_and_sibling_and_degree
set_height(root)
set_depth(root, 0)
set_type

$nodes.sort.each do |key, val|
  puts "node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s" % [key, val.parent, val.sibling, val.degree, val.depth, val.height, val.type]
end
