from collections import deque
N=int(input())
color=["w"]*(N+1)
start=[None]*(N+1)
finish=[0]*(N+1)
rinsetu=[[] for i in range(N+1)]
for i in range(1,N+1):
    a=list(map(int,input().split()))
    a=a[2:]
    rinsetu[i]=a
def dfs(i,t):
    if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t
t=dfs(1,0)
while(None in start[1:]):
    a=start[1:].index(None)
    t=dfs(a+1,t)

for i in range(1,N+1):
    print("%d %d %d" %(i,start[i],finish[i]))
 from collections import deque N=int(input()) N int(input()) int input() input color=["w"]*(N+1) color ["w"]*(N+1) ["w"] "w" N+1 N 1 start=[None]*(N+1) start [None]*(N+1) [None] None N+1 N 1 finish=[0]*(N+1) finish [0]*(N+1) [0] 0 N+1 N 1 [] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [] rinsetu=[[] for i in range(N+1)] rinsetu [[] for i in range(N+1)] for i in range(1,N+1):
    a=list(map(int,input().split()))
    a=a[2:]
    rinsetu[i]=a i range(1,N+1) range 1 N+1 N 1 a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a=a[2:] a a[2:] a 2: 2 rinsetu[i]=a rinsetu[i] rinsetu i a def dfs(i,t):
    if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t dfs if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t color[i]=="w" color[i] color i "w" t+=1 t 1 start[i]=t start[i] start i t color[i]="g" color[i] color i "g" for j in rinsetu[i]:
            t=dfs(j,t)
         j rinsetu[i] rinsetu i t=dfs(j,t) t dfs(j,t) dfs j t t+=1 t 1 finish[i]=t finish[i] finish i t return t t i i t t t=dfs(1,0) t dfs(1,0) dfs 1 0 while(None in start[1:]):
    a=start[1:].index(None)
    t=dfs(a+1,t) None in start[1:] None start[1:] start 1: 1 a=start[1:].index(None) a start[1:].index(None) [1:].index [1:] start 1: 1 index None t=dfs(a+1,t) t dfs(a+1,t) dfs a+1 a 1 t for i in range(1,N+1):
    print("%d %d %d" %(i,start[i],finish[i])) i range(1,N+1) range 1 N+1 N 1 print("%d %d %d" %(i,start[i],finish[i])) print "%d %d %d" %(i,start[i],finish[i]) "%d %d %d" (i,start[i],finish[i]) i start[i] start i finish[i] finish i start=[None]*(N+1) [None]*(N+1) start t=dfs(a+1,t) dfs(a+1,t) t a=a[2:] a[2:] a a=start[1:].index(None) start[1:].index(None) a N=int(input()) int(input()) N finish=[0]*(N+1) [0]*(N+1) finish t=dfs(1,0) dfs(1,0) t color=["w"]*(N+1) ["w"]*(N+1) color def dfs(i,t):
    if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t def dfs(i,t):
    if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t dfs a=list(map(int,input().split())) list(map(int,input().split())) a rinsetu=[[] for i in range(N+1)] [[] for i in range(N+1)] rinsetu
from collections import deque
N=int(input())
color=["w"]*(N+1)
start=[None]*(N+1)
finish=[0]*(N+1)
rinsetu=[[] for i in range(N+1)]
for i in range(1,N+1):
    a=list(map(int,input().split()))
    a=a[2:]
    rinsetu[i]=a
def dfs(i,t):
    if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t
t=dfs(1,0)
while(None in start[1:]):
    a=start[1:].index(None)
    t=dfs(a+1,t)

for i in range(1,N+1):
    print("%d %d %d" %(i,start[i],finish[i]))

