n = $<.gets.to_i
Node = Struct.new(:id, :left, :right, :depth, :type, :sibling, :degree, :parent, :height)

nodes = n.times.map { Node.new(*$<.gets.split.map(&:to_i)) }.sort_by(&:id)
root = [*0...n] - nodes.flat_map {|n| [n.left, n.right]}.uniq
root = nodes[root.first]
h = nodes.map {|n| [n.id, n]}.to_h

build_tree = ->(node, depth) {
  node.depth = depth
  l, r = node.left, node.right
  degree = 0
  h1 = h2 = 0
  try = ->(next_node, s) {
    next_node.sibling = s
    next_node.parent = node.id
    build_tree.(next_node, depth + 1)
    degree += 1
    next_node.height + 1
  }
  h1 = try.(h[l], r) if l != -1
  h2 = try.(h[r], l) if r != -1
  node.degree = degree
  if l == -1 and r == -1
    node.height = 0
    node.type = "leaf"
  else
    node.height = [h1, h2].max
    node.type = "internal node"
  end
}
build_tree.(root, 0)

root.type = "root"
root.sibling = -1
root.parent = -1

puts nodes.map {|n| "node #{n.id}: parent = #{n.parent}, sibling = #{n.sibling}, " +
  "degree = #{n.degree}, depth = #{n.depth}, height = #{n.height}, #{n.type}"}

