cnt = 1
def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
    

n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
s_cnt = [0 for i in range(n)]
f_cnt = [0 for i in range(n)]

for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
        
for i in range(n):
    if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i)

for i in range(n):
    print(i+1,s_cnt[i],f_cnt[i]) cnt = 1 cnt 1 def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
     dep global cnt s_cnt[np] = cnt s_cnt[np] s_cnt np cnt cnt += 1 cnt 1 for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
     i range(n) range n if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
     G[np][i] == 1 and s_cnt[i] == 0 G[np][i] == 1 G[np][i] [np] G np i 1 s_cnt[i] == 0 s_cnt[i] s_cnt i 0 dep(G,s_cnt,f_cnt,i) dep G s_cnt f_cnt i f_cnt[np] = cnt f_cnt[np] f_cnt np cnt cnt += 1 cnt 1 G G s_cnt s_cnt f_cnt f_cnt np np n = int(input()) n int(input()) int input() input [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] G = [[0 for i in range(n)] for j in range(n)] G [[0 for i in range(n)] for j in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 s_cnt = [0 for i in range(n)] s_cnt [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f_cnt = [0 for i in range(n)] f_cnt [0 for i in range(n)] for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
         i range(n) range n S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split tmp_n = S[1] tmp_n S[1] S 1 for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
         j range(tmp_n) range tmp_n G[i][S[j+2]-1] = 1 G[i][S[j+2]-1] [i] G i S[j+2]-1 S[j+2] S j+2 j 2 1 1 for i in range(n):
    if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i) i range(n) range n if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i) s_cnt[i]==0 s_cnt[i] s_cnt i 0 dep(G,s_cnt,f_cnt,i) dep G s_cnt f_cnt i for i in range(n):
    print(i+1,s_cnt[i],f_cnt[i]) i range(n) range n print(i+1,s_cnt[i],f_cnt[i]) print i+1 i 1 s_cnt[i] s_cnt i f_cnt[i] f_cnt i def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
     def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
     dep f_cnt = [0 for i in range(n)] [0 for i in range(n)] f_cnt tmp_n = S[1] S[1] tmp_n G = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] G n = int(input()) int(input()) n S = list(map(int, input().split())) list(map(int, input().split())) S cnt = 1 1 cnt s_cnt = [0 for i in range(n)] [0 for i in range(n)] s_cnt
cnt = 1
def dep(G,s_cnt,f_cnt,np):
    global cnt
    s_cnt[np] = cnt
    cnt += 1
    for i in range(n):
        if G[np][i] == 1 and s_cnt[i] == 0:
            dep(G,s_cnt,f_cnt,i)
    f_cnt[np] = cnt
    cnt += 1
    

n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
s_cnt = [0 for i in range(n)]
f_cnt = [0 for i in range(n)]

for i in range(n):
    S = list(map(int, input().split()))
    tmp_n = S[1]
    for j in range(tmp_n):
        G[i][S[j+2]-1] = 1
        
for i in range(n):
    if s_cnt[i]==0:
        dep(G,s_cnt,f_cnt,i)

for i in range(n):
    print(i+1,s_cnt[i],f_cnt[i])
