#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def walk(index, tm, L, d, f):
    tm += 1
    d[index] = tm
    for i in L[index]:
        if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
    tm += 1
    f[index] = tm
    return tm


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [0] * num
    f = [0] * num
    tm = 0
    for i in xrange(num):
        if not d[i]:
            tm = walk(i, tm, L, d, f)

    for i in xrange(num):
        print(i+1, d[i], f[i])


main() from __future__ import division, print_function from sys import stdin def walk(index, tm, L, d, f):
    tm += 1
    d[index] = tm
    for i in L[index]:
        if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
    tm += 1
    f[index] = tm
    return tm walk tm += 1 tm 1 d[index] = tm d[index] d index tm for i in L[index]:
        if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
     i L[index] L index if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
     not d[i-1] d[i-1] d i-1 i 1 tm = walk(i-1, tm, L, d, f) tm walk(i-1, tm, L, d, f) walk i-1 i 1 tm L d f tm += 1 tm 1 f[index] = tm f[index] f index tm return tm tm index index tm tm L L d d f f def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [0] * num
    f = [0] * num
    tm = 0
    for i in xrange(num):
        if not d[i]:
            tm = walk(i, tm, L, d, f)

    for i in xrange(num):
        print(i+1, d[i], f[i]) main num = int(stdin.readline()) num int(stdin.readline()) int stdin.readline() stdin.readline stdin readline L = [] L [] for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

     _ xrange(num) xrange num int(s) for s in stdin.readline().split()[2:] for s in stdin.readline().split()[2:] s stdin.readline().split()[2:] stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split 2: 2 for s in stdin.readline().split()[2:] int(s) int s L.append([int(s) for s in stdin.readline().split()[2:]]) L.append L append [int(s) for s in stdin.readline().split()[2:]] d = [0] * num d [0] * num [0] 0 num f = [0] * num f [0] * num [0] 0 num tm = 0 tm 0 for i in xrange(num):
        if not d[i]:
            tm = walk(i, tm, L, d, f)

     i xrange(num) xrange num if not d[i]:
            tm = walk(i, tm, L, d, f)

     not d[i] d[i] d i tm = walk(i, tm, L, d, f) tm walk(i, tm, L, d, f) walk i tm L d f for i in xrange(num):
        print(i+1, d[i], f[i]) i xrange(num) xrange num print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i main() main def walk(index, tm, L, d, f):
    tm += 1
    d[index] = tm
    for i in L[index]:
        if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
    tm += 1
    f[index] = tm
    return tm def walk(index, tm, L, d, f):
    tm += 1
    d[index] = tm
    for i in L[index]:
        if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
    tm += 1
    f[index] = tm
    return tm walk def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [0] * num
    f = [0] * num
    tm = 0
    for i in xrange(num):
        if not d[i]:
            tm = walk(i, tm, L, d, f)

    for i in xrange(num):
        print(i+1, d[i], f[i]) def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [0] * num
    f = [0] * num
    tm = 0
    for i in xrange(num):
        if not d[i]:
            tm = walk(i, tm, L, d, f)

    for i in xrange(num):
        print(i+1, d[i], f[i]) main
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def walk(index, tm, L, d, f):
    tm += 1
    d[index] = tm
    for i in L[index]:
        if not d[i-1]:
            tm = walk(i-1, tm, L, d, f)
    tm += 1
    f[index] = tm
    return tm


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [0] * num
    f = [0] * num
    tm = 0
    for i in xrange(num):
        if not d[i]:
            tm = walk(i, tm, L, d, f)

    for i in xrange(num):
        print(i+1, d[i], f[i])


main()