import scala.collection.mutable
import scala.io.StdIn.{readInt, readLine}

case class Tree(id: Int, left: Option[Int], right: Option[Int])
case class Node(
    id: Int,
    parent: Option[Int],
    sibling: Option[Int],
    degree: Int,
    depth: Int,
    height: Int
)

object Main extends App {
  import Solver.solve

  val n     = readInt()
  val lines = Iterator.fill(n)(readLine())

  val xs = solve(lines, n)

  xs.foreach {
    case Node(id, parent, sibling, degree, depth, height) =>
      val p        = parent.getOrElse(-1)
      val sib      = sibling.getOrElse(-1)
      val typeName =
        if (p == -1) "root"
        else if (degree == 0) "leaf"
        else "internal node"

      println(
        s"node $id: parent = $p, sibling = $sib, degree = $degree, depth = $depth, height = $height, $typeName"
      )
  }
}

object Solver {
  def solve(lines: Iterator[String], n: Int): Array[Node] = {

    val (trees, siblings, rootId) = {
      val trees       = mutable.Map.empty[Int, Tree]
      val siblings    = mutable.Map.empty[Int, Int]
      val allChildren = mutable.Set(0 until n: _*)

      for {
        line           <- lines
        Array(id, l, r) = line.split(' ').map { _.toInt }
      } {
        val left = if (l != -1) {
          siblings(l) = r
          allChildren -= l
          Some(l)
        } else None

        val right = if (r != -1) {
          siblings(r) = l
          allChildren -= r
          Some(r)
        } else None

        trees(id) = Tree(id, left, right)
      }

      val rootId = allChildren.head
      (trees, siblings, rootId)
    }

    val xs = new Array[Node](n)
    val hs = mutable.Map.empty[Int, Int]

    def getHeight(id: Int): Int =
      if (hs.contains(id)) hs(id)
      else {
        val Tree(_, left, right) = trees(id)

        val children = Seq(left, right).flatten

        val h =
          if (children.isEmpty) 0
          else children.map { getHeight(_) + 1 }.max

        hs(id) = h
        h
      }

    def setDepth(id: Int, parent: Option[Int], depth: Int): Unit = {
      val Tree(_, left, right) = trees(id)

      val children = Seq(left, right).flatten
      val degree   = children.length
      val sibling  = siblings.get(id)
      val height   = getHeight(id)
      xs(id) = Node(id, parent, sibling, degree, depth, height)

      val p = Some(id)
      val d = depth + 1
      for (childNodeId <- children) {
        setDepth(childNodeId, p, d)
      }
    }

    setDepth(rootId, None, 0)

    xs
  }
}

