n=int(input())
E=[0]*n
for _ in range(n):
    u,k,*V=map(int,input().split())
    E[u-1]=sorted(V)[::-1]
todo=[1]
seen=[0]*n
d=[0]*n
f=[0]*n
t=0
while 0 in f:
    if not todo:
        todo.append(seen.index(0)+1)    
    if seen[todo[-1]-1]==0:
        seen[todo[-1]-1]=1
        t+=1
        d[todo[-1]-1]=t
        for v in E[todo[-1]-1]:
            if d[v-1]==0:
                todo.append(v)
    elif f[todo[-1]-1]==0:
        t+=1
        f[todo.pop()-1]=t
    else:
        todo.pop()
for i in range(n):
    print(i+1,d[i],f[i]) n=int(input()) n int(input()) int input() input E=[0]*n E [0]*n [0] 0 n for _ in range(n):
    u,k,*V=map(int,input().split())
    E[u-1]=sorted(V)[::-1] _ range(n) range n u,k,*V=map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *V V E[u-1]=sorted(V)[::-1] E[u-1] E u-1 u 1 sorted(V)[::-1] (V) sorted V ::-1 -1 todo=[1] todo [1] 1 seen=[0]*n seen [0]*n [0] 0 n d=[0]*n d [0]*n [0] 0 n f=[0]*n f [0]*n [0] 0 n t=0 t 0 while 0 in f:
    if not todo:
        todo.append(seen.index(0)+1)    
    if seen[todo[-1]-1]==0:
        seen[todo[-1]-1]=1
        t+=1
        d[todo[-1]-1]=t
        for v in E[todo[-1]-1]:
            if d[v-1]==0:
                todo.append(v)
    elif f[todo[-1]-1]==0:
        t+=1
        f[todo.pop()-1]=t
    else:
        todo.pop() 0 in f 0 f if not todo:
        todo.append(seen.index(0)+1)    
     not todo todo todo.append(seen.index(0)+1) todo.append todo append seen.index(0)+1 seen.index(0) seen.index seen index 0 1 if seen[todo[-1]-1]==0:
        seen[todo[-1]-1]=1
        t+=1
        d[todo[-1]-1]=t
        for v in E[todo[-1]-1]:
            if d[v-1]==0:
                todo.append(v)
    elif f[todo[-1]-1]==0:
        t+=1
        f[todo.pop()-1]=t
    else:
        todo.pop() seen[todo[-1]-1]==0 seen[todo[-1]-1] seen todo[-1]-1 todo[-1] todo -1 1 0 seen[todo[-1]-1]=1 seen[todo[-1]-1] seen todo[-1]-1 todo[-1] todo -1 1 1 t+=1 t 1 d[todo[-1]-1]=t d[todo[-1]-1] d todo[-1]-1 todo[-1] todo -1 1 t for v in E[todo[-1]-1]:
            if d[v-1]==0:
                todo.append(v)
     v E[todo[-1]-1] E todo[-1]-1 todo[-1] todo -1 1 if d[v-1]==0:
                todo.append(v)
     d[v-1]==0 d[v-1] d v-1 v 1 0 todo.append(v) todo.append todo append v elif f[todo[-1]-1]==0:
        t+=1
        f[todo.pop()-1]=t
     f[todo[-1]-1]==0 f[todo[-1]-1] f todo[-1]-1 todo[-1] todo -1 1 0 t+=1 t 1 f[todo.pop()-1]=t f[todo.pop()-1] f todo.pop()-1 todo.pop() todo.pop todo pop 1 t todo.pop() todo.pop todo pop for i in range(n):
    print(i+1,d[i],f[i]) i range(n) range n print(i+1,d[i],f[i]) print i+1 i 1 d[i] d i f[i] f i k,*V=map(int,input().split()) map(int,input().split()) k t=0 0 t t+=1 1 t seen=[0]*n [0]*n seen d=[0]*n [0]*n d f=[0]*n [0]*n f E=[0]*n [0]*n E todo=[1] [1] todo n=int(input()) int(input()) n u,k,*V=map(int,input().split()) map(int,input().split()) u t+=1 1 t
n=int(input())
E=[0]*n
for _ in range(n):
    u,k,*V=map(int,input().split())
    E[u-1]=sorted(V)[::-1]
todo=[1]
seen=[0]*n
d=[0]*n
f=[0]*n
t=0
while 0 in f:
    if not todo:
        todo.append(seen.index(0)+1)    
    if seen[todo[-1]-1]==0:
        seen[todo[-1]-1]=1
        t+=1
        d[todo[-1]-1]=t
        for v in E[todo[-1]-1]:
            if d[v-1]==0:
                todo.append(v)
    elif f[todo[-1]-1]==0:
        t+=1
        f[todo.pop()-1]=t
    else:
        todo.pop()
for i in range(n):
    print(i+1,d[i],f[i])
