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

case class Node(id: Int, parent: Int, depth: Int, children: List[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, depth, children) =>
      val typeName =
        if (parent == -1) "root"
        else if (children.isEmpty) "leaf"
        else "internal node"

      val cs = children.mkString("[", ", ", "]")
      println(s"node $id: parent = $parent, depth = $depth, $typeName, $cs")
  }
}

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

    val (childrenMap, rootId) = {
      val childrenMap = mutable.Map.empty[Int, List[Int]]
      val allChildren = mutable.Set(0 until n: _*)
      for {
        line               <- lines
        id :: _ :: children = line.split(' ').map { _.toInt }.toList
      } {
        childrenMap(id) = children
        allChildren --= children
      }

      val rootId = allChildren.head
      (childrenMap, rootId)
    }

    val xs = new Array[Node](n)
    def setDepth(id: Int, parent: Int, depth: Int): Unit = {
      val children = childrenMap(id)
      xs(id) = Node(id, parent, depth, children)

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

    setDepth(rootId, -1, 0)

    xs
  }
}

