import scala.io.Source.stdin

case class Node(
  id: Int,
  children: List[Int],
  parent: Int = -1,
  depth: Int = 0
) {
  override def toString() = {
    val name = if (depth == 0) {
      "root"
    } else if (children.length > 0) {
      "internal node"
    } else {
      "leaf"
    }
    s"node $id: parent = $parent, depth = $depth, ${ name }, [${children.mkString(", ")}]"
  }
}

object Main {
  def main(argv: Array[String]) = {
    val head :: tail = stdin.getLines.toList
    val count = head.toInt
    val nodes = new Array[Node](count)

    tail.foreach { line =>
      val id :: count :: children = line.split(" ").map(_.toInt).toList
      nodes(id) = Node(id, children)
    }

    nodes foreach { node =>
      node.children.foreach { id =>
        val child = nodes(id)
        nodes(id) = child.copy(parent = node.id)
      }
    }

    nodes.find(n => n.parent == -1).foreach { root =>
      recursive(0, root, nodes)
    }

    nodes.foreach { node =>
      println(node)
    }
  }

  def recursive(currentDepth: Int, node: Node, nodes: Array[Node]): Unit = {
    node.children.foreach { id =>
      nodes(id) = nodes(id).copy(depth = currentDepth + 1)
    }

    node.children.foreach { id =>
      recursive(currentDepth + 1, nodes(id), nodes)
    }
  }
}

