n = int(input())
G = {i:[] for i in range(1, n+1)}
for _ in range(n):
    ukv = list(map(int, input().split()))
    u = ukv[0]
    k = ukv[1]
    for i in range(2, 2+k):
        G[u].append(ukv[i])
        
d = [-1 for _ in range(n+1)]
f = [-1 for _ in range(n+1)]
counter = 0

def dfs(n):
    global counter
    counter += 1
    d[n] = counter
    
    for n_i in G[n]:
        if d[n_i]==-1:
            dfs(n_i)
            
    counter += 1
    f[n] = counter

for i in range(1, n+1):
    if d[i]==-1:
        dfs(i)

for id_i, (d_i, f_i) in enumerate(zip(d[1:], f[1:]), 1):
    print(id_i, d_i, f_i) n = int(input()) n int(input()) int input() input i:[] for i in range(1, n+1) for i in range(1, n+1) i range(1, n+1) range 1 n+1 n 1 for i in range(1, n+1) i [] G = {i:[] for i in range(1, n+1)} G {i:[] for i in range(1, n+1)} for _ in range(n):
    ukv = list(map(int, input().split()))
    u = ukv[0]
    k = ukv[1]
    for i in range(2, 2+k):
        G[u].append(ukv[i])
         _ range(n) range n ukv = list(map(int, input().split())) ukv list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = ukv[0] u ukv[0] ukv 0 k = ukv[1] k ukv[1] ukv 1 for i in range(2, 2+k):
        G[u].append(ukv[i])
         i range(2, 2+k) range 2 2+k 2 k G[u].append(ukv[i]) [u].append [u] G u append ukv[i] ukv i -1 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) -1 d = [-1 for _ in range(n+1)] d [-1 for _ in range(n+1)] -1 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) -1 f = [-1 for _ in range(n+1)] f [-1 for _ in range(n+1)] counter = 0 counter 0 def dfs(n):
    global counter
    counter += 1
    d[n] = counter
    
    for n_i in G[n]:
        if d[n_i]==-1:
            dfs(n_i)
            
    counter += 1
    f[n] = counter dfs global counter counter += 1 counter 1 d[n] = counter d[n] d n counter for n_i in G[n]:
        if d[n_i]==-1:
            dfs(n_i)
            
     n_i G[n] G n if d[n_i]==-1:
            dfs(n_i)
            
     d[n_i]==-1 d[n_i] d n_i -1 dfs(n_i) dfs n_i counter += 1 counter 1 f[n] = counter f[n] f n counter n n for i in range(1, n+1):
    if d[i]==-1:
        dfs(i) i range(1, n+1) range 1 n+1 n 1 if d[i]==-1:
        dfs(i) d[i]==-1 d[i] d i -1 dfs(i) dfs i for id_i, (d_i, f_i) in enumerate(zip(d[1:], f[1:]), 1):
    print(id_i, d_i, f_i) id_i (d_i, f_i) d_i f_i enumerate(zip(d[1:], f[1:]), 1) enumerate zip(d[1:], f[1:]) zip d[1:] d 1: 1 f[1:] f 1: 1 1 print(id_i, d_i, f_i) print id_i d_i f_i d = [-1 for _ in range(n+1)] [-1 for _ in range(n+1)] d u = ukv[0] ukv[0] u f = [-1 for _ in range(n+1)] [-1 for _ in range(n+1)] f n = int(input()) int(input()) n def dfs(n):
    global counter
    counter += 1
    d[n] = counter
    
    for n_i in G[n]:
        if d[n_i]==-1:
            dfs(n_i)
            
    counter += 1
    f[n] = counter def dfs(n):
    global counter
    counter += 1
    d[n] = counter
    
    for n_i in G[n]:
        if d[n_i]==-1:
            dfs(n_i)
            
    counter += 1
    f[n] = counter dfs ukv = list(map(int, input().split())) list(map(int, input().split())) ukv k = ukv[1] ukv[1] k counter = 0 0 counter G = {i:[] for i in range(1, n+1)} {i:[] for i in range(1, n+1)} G
n = int(input())
G = {i:[] for i in range(1, n+1)}
for _ in range(n):
    ukv = list(map(int, input().split()))
    u = ukv[0]
    k = ukv[1]
    for i in range(2, 2+k):
        G[u].append(ukv[i])
        
d = [-1 for _ in range(n+1)]
f = [-1 for _ in range(n+1)]
counter = 0

def dfs(n):
    global counter
    counter += 1
    d[n] = counter
    
    for n_i in G[n]:
        if d[n_i]==-1:
            dfs(n_i)
            
    counter += 1
    f[n] = counter

for i in range(1, n+1):
    if d[i]==-1:
        dfs(i)

for id_i, (d_i, f_i) in enumerate(zip(d[1:], f[1:]), 1):
    print(id_i, d_i, f_i)
