import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val graph: Array[List[Int]] = new Array[List[Int]](n + 1).map(a => Nil);
        for (i <- (1 to n)) {
            graph(i) = readLine.split(" ").map(_.toInt).drop(2).toList;
        }
        val ret = Main.dfs(n + 1, graph);
        for (i <- (1 to n)) {println("%d %d %d".format(i, ret(i)(0), ret(i)(1)))}
    }
    def dfs(size: Int, graph: Array[List[Int]]): Array[Array[Int]] = {
        val ret = Array.ofDim[Int](size, 2);
        def go(stack: List[Int], cost: Int): Int = {
            stack match {
                case Nil => cost;
                case curr :: rest => {
                    ret(curr)(0) = cost;
                    val nextCost = graph(curr).foldLeft(cost + 1) { (c, i) =>
                        if (ret(i)(0) == 0) go(i :: rest, c) else c;
                    }
                    ret(curr)(1) = nextCost;
                    nextCost + 1;
                }
            }
        }
        (1 until size).foldLeft(1) { (cost, i) => if (ret(i)(0) == 0) go(List(i), cost) else cost}
        ret;
    }
}

