n=int(input())
G=[]
for i in range(n):
    u,k,*l=map(int,input().split())
    G.append(l)
#print(G)
log_finish=[0]*n
log_start=[0]*n

from collections import deque
def dfs(G):
    q=deque()
    for i in range(n,0,-1):
        q.append((i,-1,0))
    log_finish[0]=1
    log_start[0]=1
    cnt=0
    while q:
        #print(q,cnt)
        V,P,S=q.pop()
        if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1]

dfs(G)
for i in range(n):
    print(i+1,log_start[i],log_finish[i]) n=int(input()) n int(input()) int input() input G=[] G [] for i in range(n):
    u,k,*l=map(int,input().split())
    G.append(l)
#print(G) i range(n) range n u,k,*l=map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *l l G.append(l) G.append G append l log_finish=[0]*n log_finish [0]*n [0] 0 n log_start=[0]*n log_start [0]*n [0] 0 n from collections import deque def dfs(G):
    q=deque()
    for i in range(n,0,-1):
        q.append((i,-1,0))
    log_finish[0]=1
    log_start[0]=1
    cnt=0
    while q:
        #print(q,cnt)
        V,P,S=q.pop()
        if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1] dfs q=deque() q deque() deque for i in range(n,0,-1):
        q.append((i,-1,0))
     i range(n,0,-1) range n 0 -1 q.append((i,-1,0)) q.append q append (i,-1,0) i -1 0 log_finish[0]=1 log_finish[0] log_finish 0 1 log_start[0]=1 log_start[0] log_start 0 1 cnt=0 cnt 0 while q:
        #print(q,cnt)
        V,P,S=q.pop()
        if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1] q V,P,S=q.pop() V q.pop() q.pop q pop P S if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


         log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1] log_finish[V-1]==0 log_finish[V-1] log_finish V-1 V 1 0 log_finish[V-1]==log_start[V-1] log_finish[V-1] log_finish V-1 V 1 log_start[V-1] log_start V-1 V 1 cnt+=1 cnt 1 if not log_finish[V-1]:log_start[V-1]=cnt
             not log_finish[V-1] log_finish[V-1] log_finish V-1 V 1 log_finish[V-1]=cnt log_finish[V-1] log_finish V-1 V 1 cnt if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1] S==0 S 0 q.append((V,P,1)) q.append q append (V,P,1) V P 1 l=[] l [] if not G[V-1]:continue
             not G[V-1] G[V-1] G V-1 V 1 for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
             new_v G[V-1] G V-1 V 1 if log_start[new_v-1]!=0:continue
                 log_start[new_v-1]!=0 log_start[new_v-1] log_start new_v-1 new_v 1 0 l.append((new_v,V,0)) l.append l append (new_v,V,0) new_v V 0 q+=l[::-1] q l[::-1] l ::-1 -1 G G dfs(G) dfs G for i in range(n):
    print(i+1,log_start[i],log_finish[i]) i range(n) range n print(i+1,log_start[i],log_finish[i]) print i+1 i 1 log_start[i] log_start i log_finish[i] log_finish i G=[] [] G k,*l=map(int,input().split()) map(int,input().split()) k n=int(input()) int(input()) n log_finish=[0]*n [0]*n log_finish log_start=[0]*n [0]*n log_start def dfs(G):
    q=deque()
    for i in range(n,0,-1):
        q.append((i,-1,0))
    log_finish[0]=1
    log_start[0]=1
    cnt=0
    while q:
        #print(q,cnt)
        V,P,S=q.pop()
        if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1] def dfs(G):
    q=deque()
    for i in range(n,0,-1):
        q.append((i,-1,0))
    log_finish[0]=1
    log_start[0]=1
    cnt=0
    while q:
        #print(q,cnt)
        V,P,S=q.pop()
        if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1] dfs u,k,*l=map(int,input().split()) map(int,input().split()) u
n=int(input())
G=[]
for i in range(n):
    u,k,*l=map(int,input().split())
    G.append(l)
#print(G)
log_finish=[0]*n
log_start=[0]*n

from collections import deque
def dfs(G):
    q=deque()
    for i in range(n,0,-1):
        q.append((i,-1,0))
    log_finish[0]=1
    log_start[0]=1
    cnt=0
    while q:
        #print(q,cnt)
        V,P,S=q.pop()
        if log_finish[V-1]==0 or log_finish[V-1]==log_start[V-1]:
            cnt+=1
            if not log_finish[V-1]:log_start[V-1]=cnt
            log_finish[V-1]=cnt
        #print(V,P,S,cnt)


        if S==0:
            #下に遷移していくときの処理
            q.append((V,P,1))
            l=[]
            if not G[V-1]:continue
            for new_v in G[V-1]:
                if log_start[new_v-1]!=0:continue
                l.append((new_v,V,0))
            q+=l[::-1]

dfs(G)
for i in range(n):
    print(i+1,log_start[i],log_finish[i])
