# =============================================================================
#　Depth First Search
# =============================================================================
import sys
sys.setrecursionlimit(10**8)

N=int(input())
Graph=[list(map(int,input().split()))[2:] for _ in range(N)]
Graph.insert(0,[])
seen=[False for _ in range(N+1)]
first_order=[0]*(N+1)
last_order=[0]*(N+1)
time=1

def dfs(Graph,v):
    global seen
    global time
    seen[v]=True
    first_order[v]=time
    time+=1
    for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

    last_order[v]=time
    time+=1

for v in range(1,N+1):
    if not seen[v]:
        dfs(Graph,v)
for i in range(1,N+1):
    print(i,first_order[i],last_order[i])
 import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 N=int(input()) N int(input()) int input() input list(map(int,input().split()))[2:] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int,input().split()))[2:] (map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 2: 2 Graph=[list(map(int,input().split()))[2:] for _ in range(N)] Graph [list(map(int,input().split()))[2:] for _ in range(N)] Graph.insert(0,[]) Graph.insert Graph insert 0 [] False for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) False seen=[False for _ in range(N+1)] seen [False for _ in range(N+1)] first_order=[0]*(N+1) first_order [0]*(N+1) [0] 0 N+1 N 1 last_order=[0]*(N+1) last_order [0]*(N+1) [0] 0 N+1 N 1 time=1 time 1 def dfs(Graph,v):
    global seen
    global time
    seen[v]=True
    first_order[v]=time
    time+=1
    for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

    last_order[v]=time
    time+=1 dfs global seen global time seen[v]=True seen[v] seen v True first_order[v]=time first_order[v] first_order v time time+=1 time 1 for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

     nv Graph[v] Graph v if seen[nv]:
            continue
         seen[nv] seen nv continue dfs(Graph,nv) dfs Graph nv last_order[v]=time last_order[v] last_order v time time+=1 time 1 Graph Graph v v for v in range(1,N+1):
    if not seen[v]:
        dfs(Graph,v) v range(1,N+1) range 1 N+1 N 1 if not seen[v]:
        dfs(Graph,v) not seen[v] seen[v] seen v dfs(Graph,v) dfs Graph v for i in range(1,N+1):
    print(i,first_order[i],last_order[i]) i range(1,N+1) range 1 N+1 N 1 print(i,first_order[i],last_order[i]) print i first_order[i] first_order i last_order[i] last_order i N=int(input()) int(input()) N first_order=[0]*(N+1) [0]*(N+1) first_order last_order=[0]*(N+1) [0]*(N+1) last_order time=1 1 time def dfs(Graph,v):
    global seen
    global time
    seen[v]=True
    first_order[v]=time
    time+=1
    for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

    last_order[v]=time
    time+=1 def dfs(Graph,v):
    global seen
    global time
    seen[v]=True
    first_order[v]=time
    time+=1
    for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

    last_order[v]=time
    time+=1 dfs seen=[False for _ in range(N+1)] [False for _ in range(N+1)] seen Graph=[list(map(int,input().split()))[2:] for _ in range(N)] [list(map(int,input().split()))[2:] for _ in range(N)] Graph
# =============================================================================
#　Depth First Search
# =============================================================================
import sys
sys.setrecursionlimit(10**8)

N=int(input())
Graph=[list(map(int,input().split()))[2:] for _ in range(N)]
Graph.insert(0,[])
seen=[False for _ in range(N+1)]
first_order=[0]*(N+1)
last_order=[0]*(N+1)
time=1

def dfs(Graph,v):
    global seen
    global time
    seen[v]=True
    first_order[v]=time
    time+=1
    for nv in Graph[v]:
        if seen[nv]:
            continue
        dfs(Graph,nv)

    last_order[v]=time
    time+=1

for v in range(1,N+1):
    if not seen[v]:
        dfs(Graph,v)
for i in range(1,N+1):
    print(i,first_order[i],last_order[i])

