n=int(input())
G=[]
for i in range(n):
    L=list(map(int,input().split()))
    G.append(L[2:])
    for j in range(len(G[-1])):
        G[-1][j]-=1

Forder=[-1]*n
Lorder=[-1]*n
ptr=1
def dfs(v):
    #print(v)
    #print(G[v])
    #print()
    global ptr

    Forder[v]=ptr
    ptr+=1

    for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
    Lorder[v]=ptr
    ptr+=1

#while True:
#    #print(Forder,Lorder)
#    for i in range(n):
#        if Forder[i]!=-1 and Lorder[i]!=-1:
#            pass
#        else:
#            dfs(i)
#            continue
#
#        if i==n-1:
#            break
#    else:
#        continue
#    break
#
#for i in range(n):
#    print(i+1,Forder[i],Lorder[i])

##########
for i in range(n):
    if Forder[i]==-1 or Lorder[i]==-1:
        dfs(i)

for i in range(n):
    print(i+1,Forder[i],Lorder[i]) n=int(input()) n int(input()) int input() input G=[] G [] for i in range(n):
    L=list(map(int,input().split()))
    G.append(L[2:])
    for j in range(len(G[-1])):
        G[-1][j]-=1 i range(n) range n L=list(map(int,input().split())) L list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split G.append(L[2:]) G.append G append L[2:] L 2: 2 for j in range(len(G[-1])):
        G[-1][j]-=1 j range(len(G[-1])) range len(G[-1]) len G[-1] G -1 G[-1][j]-=1 G[-1][j] [-1] G -1 j 1 Forder=[-1]*n Forder [-1]*n [-1] -1 n Lorder=[-1]*n Lorder [-1]*n [-1] -1 n ptr=1 ptr 1 def dfs(v):
    #print(v)
    #print(G[v])
    #print()
    global ptr

    Forder[v]=ptr
    ptr+=1

    for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
    Lorder[v]=ptr
    ptr+=1

#while True:
#    #print(Forder,Lorder)
#    for i in range(n):
#        if Forder[i]!=-1 and Lorder[i]!=-1:
#            pass
#        else:
#            dfs(i)
#            continue
#
#        if i==n-1:
#            break
#    else:
#        continue
#    break
#
#for i in range(n):
#    print(i+1,Forder[i],Lorder[i])

########## dfs global ptr Forder[v]=ptr Forder[v] Forder v ptr ptr+=1 ptr 1 for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
     next G[v] G v if Forder[next]!=-1:
            continue
         Forder[next]!=-1 Forder[next] Forder next -1 continue dfs(next) dfs next Lorder[v]=ptr Lorder[v] Lorder v ptr ptr+=1 ptr 1 v v for i in range(n):
    if Forder[i]==-1 or Lorder[i]==-1:
        dfs(i) i range(n) range n if Forder[i]==-1 or Lorder[i]==-1:
        dfs(i) Forder[i]==-1 or Lorder[i]==-1 Forder[i]==-1 Forder[i] Forder i -1 Lorder[i]==-1 Lorder[i] Lorder i -1 dfs(i) dfs i for i in range(n):
    print(i+1,Forder[i],Lorder[i]) i range(n) range n print(i+1,Forder[i],Lorder[i]) print i+1 i 1 Forder[i] Forder i Lorder[i] Lorder i Forder=[-1]*n [-1]*n Forder L=list(map(int,input().split())) list(map(int,input().split())) L G=[] [] G Lorder=[-1]*n [-1]*n Lorder ptr=1 1 ptr def dfs(v):
    #print(v)
    #print(G[v])
    #print()
    global ptr

    Forder[v]=ptr
    ptr+=1

    for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
    Lorder[v]=ptr
    ptr+=1

#while True:
#    #print(Forder,Lorder)
#    for i in range(n):
#        if Forder[i]!=-1 and Lorder[i]!=-1:
#            pass
#        else:
#            dfs(i)
#            continue
#
#        if i==n-1:
#            break
#    else:
#        continue
#    break
#
#for i in range(n):
#    print(i+1,Forder[i],Lorder[i])

########## def dfs(v):
    #print(v)
    #print(G[v])
    #print()
    global ptr

    Forder[v]=ptr
    ptr+=1

    for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
    Lorder[v]=ptr
    ptr+=1

#while True:
#    #print(Forder,Lorder)
#    for i in range(n):
#        if Forder[i]!=-1 and Lorder[i]!=-1:
#            pass
#        else:
#            dfs(i)
#            continue
#
#        if i==n-1:
#            break
#    else:
#        continue
#    break
#
#for i in range(n):
#    print(i+1,Forder[i],Lorder[i])

########## dfs n=int(input()) int(input()) n
n=int(input())
G=[]
for i in range(n):
    L=list(map(int,input().split()))
    G.append(L[2:])
    for j in range(len(G[-1])):
        G[-1][j]-=1

Forder=[-1]*n
Lorder=[-1]*n
ptr=1
def dfs(v):
    #print(v)
    #print(G[v])
    #print()
    global ptr

    Forder[v]=ptr
    ptr+=1

    for next in G[v]:
        if Forder[next]!=-1:
            continue
        dfs(next)
    
    Lorder[v]=ptr
    ptr+=1

#while True:
#    #print(Forder,Lorder)
#    for i in range(n):
#        if Forder[i]!=-1 and Lorder[i]!=-1:
#            pass
#        else:
#            dfs(i)
#            continue
#
#        if i==n-1:
#            break
#    else:
#        continue
#    break
#
#for i in range(n):
#    print(i+1,Forder[i],Lorder[i])

##########
for i in range(n):
    if Forder[i]==-1 or Lorder[i]==-1:
        dfs(i)

for i in range(n):
    print(i+1,Forder[i],Lorder[i])
