n = int(input())

adj = [0]*n # adjacent list

for i in range(n):
    tmp = list(map( int, input().split() ) )
    adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:]))

c = ['w']*n # color of each vertex
d = [0]*n # discovery time for each vertex
f = [0]*n  # finish time for each vertex
time = 0

def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
    
for u in range(n):
    if c[u] == 'w':
        DFS_visit(u)
        
        
for u in range(n):
    print(f"{u+1} {d[u]} {f[u]}") n = int(input()) n int(input()) int input() input adj = [0]*n adj [0]*n [0] 0 n for i in range(n):
    tmp = list(map( int, input().split() ) )
    adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:])) i range(n) range n tmp = list(map( int, input().split() ) ) tmp list(map( int, input().split() ) ) list map( int, input().split() ) map int input().split() ().split () input split adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:])) adj[tmp[0]-1] adj tmp[0]-1 tmp[0] tmp 0 1 list(map(lambda x : x - 1, tmp[2:])) list map(lambda x : x - 1, tmp[2:]) map lambda x : x - 1 x - 1 x 1 x tmp[2:] tmp 2: 2 c = ['w']*n c ['w']*n ['w'] 'w' n d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n time = 0 time 0 def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
     DFS_visit global time time += 1 time 1 d[u] = time d[u] d u time c[u] = 'g' c[u] c u 'g' for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
     v adj[u] adj u if c[v] == 'w':
            DFS_visit(v)
     c[v] == 'w' c[v] c v 'w' DFS_visit(v) DFS_visit v c[u] = 'b' c[u] c u 'b' time += 1 time 1 f[u] = time f[u] f u time u u for u in range(n):
    if c[u] == 'w':
        DFS_visit(u)
        
         u range(n) range n if c[u] == 'w':
        DFS_visit(u)
        
         c[u] == 'w' c[u] c u 'w' DFS_visit(u) DFS_visit u for u in range(n):
    print(f"{u+1} {d[u]} {f[u]}") u range(n) range n print(f"{u+1} {d[u]} {f[u]}") print f"{u+1} {d[u]} {f[u]}" f = [0]*n [0]*n f d = [0]*n [0]*n d time = 0 0 time c = ['w']*n ['w']*n c tmp = list(map( int, input().split() ) ) list(map( int, input().split() ) ) tmp n = int(input()) int(input()) n adj = [0]*n [0]*n adj def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
     def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
     DFS_visit
n = int(input())

adj = [0]*n # adjacent list

for i in range(n):
    tmp = list(map( int, input().split() ) )
    adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:]))

c = ['w']*n # color of each vertex
d = [0]*n # discovery time for each vertex
f = [0]*n  # finish time for each vertex
time = 0

def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
    
for u in range(n):
    if c[u] == 'w':
        DFS_visit(u)
        
        
for u in range(n):
    print(f"{u+1} {d[u]} {f[u]}")
