object Main {
  def main(args: Array[String]): Unit = {
    val n: Int = io.StdIn.readInt()
    val children: Array[Seq[Int]] = Array.fill(n)(Seq(-1,-1))
    val parent: Array[Option[Int]] = Array.fill(n)(None)

    for {
      _ <- 0 until n
      l = io.StdIn.readLine()
    } {
      val Seq(i, c1, c2): Seq[Int] = l.split(" ", 3).map(_.toInt)
      children(i) = Seq(c1, c2)
      if (c1 != -1) parent(c1) = Some(i)
      if (c2 != -1) parent(c2) = Some(i)
    }

    def depth: Memoized = Memoized {i =>
      parent(i) match {
        case None => 0
        case Some(x) => 1 + depth(x)
      }
    }
    def height: Memoized = Memoized {i =>
      children(i) match {
        case Seq(-1, -1) => 0
        case Seq(x,  -1) => 1 + height(x)
        case Seq(-1,  y) => 1 + height(y)
        case Seq(x,   y) => 1 + (height(x) max height(y))
      }
    }

    for (i <- 0 until n) {
      val p: Int = parent(i).getOrElse(-1)
      val s: Int = if (p == -1) -1 else children(p).filterNot(_ == i).head
      val deg: Int = children(i).filterNot(_ == -1).length
      val t = if (p == -1) "root" else if (deg == 0) "leaf" else "internal node"

      println(s"node $i: parent = $p, sibling = $s, degree = $deg, depth = ${depth(i)}, height = ${height(i)}, $t")
    }
  }

  case class Memoized(f: Int => Int) extends (Int => Int) {
    val cache: Array[Option[Int]] = Array.fill(256)(None)
    def apply(i: Int): Int = cache(i) match {
      case None => cache(i) = Some(f(i)); cache(i).get
      case Some(x) => x
    }
  }
}