#連結グラフではない
n = int(input())
V = [[] for _ in range(n+1)]
for _ in range(n):
    inpt = list(map(int,input().split( )))
    if len(inpt)>2:
        V[inpt[0]] = inpt[2:]


D = [0]*(n+1)
F = [0]*(n+1)

time = 1
Q = [1]
D[0] = -1
D[1] = 1
while len(Q) > 0 or 0 in D[1:]:
    v = Q[-1]
    remains = False
    for i in V[v]:
        if D[i] == 0:
            D[i] = time+1
            Q.append(i)
            remains = True
            break
    if not remains:
        F[v] = time+1
        Q.pop()
        
    time += 1
    if len(Q) == 0:
        if 0 in D:
            time += 1
            nxt = D.index(0)
            Q.append(nxt)
            D[nxt] = time
        else:
            pass
        

for i in range(1,n+1):
    print(i,D[i],F[i])
 n = int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] V = [[] for _ in range(n+1)] V [[] for _ in range(n+1)] for _ in range(n):
    inpt = list(map(int,input().split( )))
    if len(inpt)>2:
        V[inpt[0]] = inpt[2:] _ range(n) range n inpt = list(map(int,input().split( ))) inpt list(map(int,input().split( ))) list map(int,input().split( )) map int input().split( ) ().split () input split if len(inpt)>2:
        V[inpt[0]] = inpt[2:] len(inpt)>2 len(inpt) len inpt 2 V[inpt[0]] = inpt[2:] V[inpt[0]] V inpt[0] inpt 0 inpt[2:] inpt 2: 2 D = [0]*(n+1) D [0]*(n+1) [0] 0 n+1 n 1 F = [0]*(n+1) F [0]*(n+1) [0] 0 n+1 n 1 time = 1 time 1 Q = [1] Q [1] 1 D[0] = -1 D[0] D 0 -1 D[1] = 1 D[1] D 1 1 while len(Q) > 0 or 0 in D[1:]:
    v = Q[-1]
    remains = False
    for i in V[v]:
        if D[i] == 0:
            D[i] = time+1
            Q.append(i)
            remains = True
            break
    if not remains:
        F[v] = time+1
        Q.pop()
        
    time += 1
    if len(Q) == 0:
        if 0 in D:
            time += 1
            nxt = D.index(0)
            Q.append(nxt)
            D[nxt] = time
        else:
            pass
         len(Q) > 0 or 0 in D[1:] len(Q) > 0 len(Q) len Q 0 0 in D[1:] 0 D[1:] D 1: 1 v = Q[-1] v Q[-1] Q -1 remains = False remains False for i in V[v]:
        if D[i] == 0:
            D[i] = time+1
            Q.append(i)
            remains = True
            break
     i V[v] V v if D[i] == 0:
            D[i] = time+1
            Q.append(i)
            remains = True
            break
     D[i] == 0 D[i] D i 0 D[i] = time+1 D[i] D i time+1 time 1 Q.append(i) Q.append Q append i remains = True remains True break if not remains:
        F[v] = time+1
        Q.pop()
        
     not remains remains F[v] = time+1 F[v] F v time+1 time 1 Q.pop() Q.pop Q pop time += 1 time 1 if len(Q) == 0:
        if 0 in D:
            time += 1
            nxt = D.index(0)
            Q.append(nxt)
            D[nxt] = time
        else:
            pass
         len(Q) == 0 len(Q) len Q 0 if 0 in D:
            time += 1
            nxt = D.index(0)
            Q.append(nxt)
            D[nxt] = time
        else:
            pass
         0 in D 0 D time += 1 time 1 nxt = D.index(0) nxt D.index(0) D.index D index 0 Q.append(nxt) Q.append Q append nxt D[nxt] = time D[nxt] D nxt time for i in range(1,n+1):
    print(i,D[i],F[i]) i range(1,n+1) range 1 n+1 n 1 print(i,D[i],F[i]) print i D[i] D i F[i] F i v = Q[-1] Q[-1] v remains = False False remains F = [0]*(n+1) [0]*(n+1) F time += 1 1 time V = [[] for _ in range(n+1)] [[] for _ in range(n+1)] V time = 1 1 time nxt = D.index(0) D.index(0) nxt Q = [1] [1] Q remains = True True remains inpt = list(map(int,input().split( ))) list(map(int,input().split( ))) inpt n = int(input()) int(input()) n D = [0]*(n+1) [0]*(n+1) D time += 1 1 time
#連結グラフではない
n = int(input())
V = [[] for _ in range(n+1)]
for _ in range(n):
    inpt = list(map(int,input().split( )))
    if len(inpt)>2:
        V[inpt[0]] = inpt[2:]


D = [0]*(n+1)
F = [0]*(n+1)

time = 1
Q = [1]
D[0] = -1
D[1] = 1
while len(Q) > 0 or 0 in D[1:]:
    v = Q[-1]
    remains = False
    for i in V[v]:
        if D[i] == 0:
            D[i] = time+1
            Q.append(i)
            remains = True
            break
    if not remains:
        F[v] = time+1
        Q.pop()
        
    time += 1
    if len(Q) == 0:
        if 0 in D:
            time += 1
            nxt = D.index(0)
            Q.append(nxt)
            D[nxt] = time
        else:
            pass
        

for i in range(1,n+1):
    print(i,D[i],F[i])

