import scala.io.StdIn.{readInt, readLine}
case class Node[T](value: T, parent: Node[T], var children: List[Node[T]], depth: Int) {
    override def toString(): String = {
        val p = if (parent == null) -1 else parent.value
        val t = if (parent == null) "root" else if (children == Nil) "leaf" else "internal node"
        val c = children.map(_.value).mkString(",")
        s"node ${value}: parent = ${p}, depth = ${depth}, ${t}, [${c}]"
    }
}
class IntTree() {
    var node: Node[Int] = null
    
    def add(target: Int, c: List[Int]): Unit = {
        if (node == null) {
            node = new Node[Int](target, null,  Nil, 0)
            node.children = c.map(new Node[Int](_, node, Nil, 1))
        } else search(target) match {
            case n => n.children = c.map(new Node[Int](_, n, Nil, n.depth + 1))
        }
    }

    def search(target: Int): Node[Int] = {
        def go(nodes: List[Node[Int]]): Node[Int] = nodes match {
            case Nil => null
            case x :: xs if x.value == target => x
            case x :: xs => go(x.children) match {
                case null => go(xs)
                case ret => ret
            }
        }
        if (node.value == target) node else go(node.children)
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val t = new IntTree()
        val l = (0 until len).foldLeft(Nil: List[Int]) { (list, i) =>
            val line = readLine.split(" ").map(_.toInt)
            val c = line.slice(2, line.length).toList
            val p = line.head
            t.add(p, c)
            if (i == 0) (p :: c) ::: list
            else c ::: list
        }
        println(l.sorted.map(t.search(_)).mkString("\n"))
    }
}
