n=int(input())
seen=[-1]*n
first_order=[0]*n
last_order=[0]*n
cnt=0
def dfs(G,s):
    global cnt
    first_order[s]=cnt+1
    cnt+=1
    seen[s]=1
    for nv in G[s]:
        if(seen[nv]!=-1):
            continue
        dfs(G,nv)
    last_order[s]=cnt+1
    cnt+=1

G=[[] for i in range(n)]
for i in range(n):
    li=list(map(int,input().split()))
    for x in range(2,len(li)):
        G[i].append(li[x]-1)
for i in range(n):
    if(seen[i]==-1):
        dfs(G,i)
for i in range(n):
    print(i+1,first_order[i],last_order[i]) n=int(input()) n int(input()) int input() input seen=[-1]*n seen [-1]*n [-1] -1 n first_order=[0]*n first_order [0]*n [0] 0 n last_order=[0]*n last_order [0]*n [0] 0 n cnt=0 cnt 0 def dfs(G,s):
    global cnt
    first_order[s]=cnt+1
    cnt+=1
    seen[s]=1
    for nv in G[s]:
        if(seen[nv]!=-1):
            continue
        dfs(G,nv)
    last_order[s]=cnt+1
    cnt+=1 dfs global cnt first_order[s]=cnt+1 first_order[s] first_order s cnt+1 cnt 1 cnt+=1 cnt 1 seen[s]=1 seen[s] seen s 1 for nv in G[s]:
        if(seen[nv]!=-1):
            continue
        dfs(G,nv)
     nv G[s] G s if(seen[nv]!=-1):
            continue
         seen[nv]!=-1 seen[nv] seen nv -1 continue dfs(G,nv) dfs G nv last_order[s]=cnt+1 last_order[s] last_order s cnt+1 cnt 1 cnt+=1 cnt 1 G G s s [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] G=[[] for i in range(n)] G [[] for i in range(n)] for i in range(n):
    li=list(map(int,input().split()))
    for x in range(2,len(li)):
        G[i].append(li[x]-1) i range(n) range n li=list(map(int,input().split())) li list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split for x in range(2,len(li)):
        G[i].append(li[x]-1) x range(2,len(li)) range 2 len(li) len li G[i].append(li[x]-1) [i].append [i] G i append li[x]-1 li[x] li x 1 for i in range(n):
    if(seen[i]==-1):
        dfs(G,i) i range(n) range n if(seen[i]==-1):
        dfs(G,i) seen[i]==-1 seen[i] seen i -1 dfs(G,i) dfs G i for i in range(n):
    print(i+1,first_order[i],last_order[i]) i range(n) range n print(i+1,first_order[i],last_order[i]) print i+1 i 1 first_order[i] first_order i last_order[i] last_order i n=int(input()) int(input()) n def dfs(G,s):
    global cnt
    first_order[s]=cnt+1
    cnt+=1
    seen[s]=1
    for nv in G[s]:
        if(seen[nv]!=-1):
            continue
        dfs(G,nv)
    last_order[s]=cnt+1
    cnt+=1 def dfs(G,s):
    global cnt
    first_order[s]=cnt+1
    cnt+=1
    seen[s]=1
    for nv in G[s]:
        if(seen[nv]!=-1):
            continue
        dfs(G,nv)
    last_order[s]=cnt+1
    cnt+=1 dfs first_order=[0]*n [0]*n first_order last_order=[0]*n [0]*n last_order G=[[] for i in range(n)] [[] for i in range(n)] G seen=[-1]*n [-1]*n seen li=list(map(int,input().split())) list(map(int,input().split())) li cnt=0 0 cnt
n=int(input())
seen=[-1]*n
first_order=[0]*n
last_order=[0]*n
cnt=0
def dfs(G,s):
    global cnt
    first_order[s]=cnt+1
    cnt+=1
    seen[s]=1
    for nv in G[s]:
        if(seen[nv]!=-1):
            continue
        dfs(G,nv)
    last_order[s]=cnt+1
    cnt+=1

G=[[] for i in range(n)]
for i in range(n):
    li=list(map(int,input().split()))
    for x in range(2,len(li)):
        G[i].append(li[x]-1)
for i in range(n):
    if(seen[i]==-1):
        dfs(G,i)
for i in range(n):
    print(i+1,first_order[i],last_order[i])
