class Node

  attr_accessor :id, :left_child, :right_sibling, :parent

  def initialize(id)
    @id= id
    # ここでデフォルト値を設定しているとバグの元になるので直したい
    @parent = -1
    @children = []
  end

  def get_depth
    depth = 0
    u = id
    until $tree[u].parent == -1 do
      depth += 1
      u = $tree[u].parent
    end
    depth
  end

  def get_height
    leaves = self.get_leaves
    if leaves.empty?
      0
    else
      leaf_max_depth = leaves.map{|i|$tree[i].get_depth}.max
      leaf_max_depth - $tree[self.id].get_depth
    end
  end

  def get_leaves
    return [self.id] if self.get_type == 'leaf'
    children = get_children
    leaves = children.map do |child|
      $tree[child].get_leaves
    end
    leaves.flatten
  end

  def get_degree
    get_children.size
  end

  def get_children
    if left_child.nil?
      []
    else
      u = left_child
      children = [u]
      until $tree[u].right_sibling == nil do
        u = $tree[u].right_sibling
        children << u
      end
      children
    end
  end

  def get_sibling
    # rootの時は、兄弟が存在しないから無条件に返す。
    return -1 if parent == -1
    sibling = $tree[parent].get_children - [self.id]
    if sibling.empty?
      -1
    else
      # 兄弟は最大一人
      sibling[0]
    end
  end

  def get_type
    if parent == -1
      'root'
    elsif get_children == []
      'leaf'
    else
      'internal node'
    end
  end
end

n = gets.to_i

$tree = {}

n.times do
  input = gets.split.map(&:to_i)
  id = input[0]
  left_child = input[1]
  right_child = input[2]

  children = [left_child, right_child].reject {|i| i == -1}
  children_count = children.size
  $tree[id] ||= Node.new(id)
  node = $tree[id]

  if children_count == 0
    node.left_child = nil
  else
    node.left_child = children[0]
    # 最後にnil入れるの扱いにくくなるから直したい。
    children.push(nil).each_cons(2) do |a, b|
      $tree[a] ||= Node.new(a)
      $tree[a].parent = id
      $tree[a].right_sibling = b if b
    end
  end
end

for i in 0..n - 1 do
  node = $tree[i]
  puts "node #{node.id}: parent = #{node.parent}, sibling = #{node.get_sibling}, degree = #{node.get_degree}, depth = #{node.get_depth}, height = #{node.get_height}, #{node.get_type}"
end

