n = int(input())
a = [None]
for i in range(n):
    adj = list(map(int,input().split()))
    a.append(adj[2:])
    
s = [None]
for i in range(1, n + 1):
    s.append([False, i])
    
time = 0

def dfs(u):
    global time
    s[u][0] = True
    time += 1
    s[u].append(time)
    
    for v in a[u]:
        if s[v][0] == False:
            dfs(v)
            
    time += 1
    s[u].append(time)
    
for i in range(1,n+1):
    if s[i][0] == False:
        dfs(i)
        
for x in s[1:]:
    print(*x[1:]) n = int(input()) n int(input()) int input() input a = [None] a [None] None for i in range(n):
    adj = list(map(int,input().split()))
    a.append(adj[2:])
     i range(n) range n adj = list(map(int,input().split())) adj list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a.append(adj[2:]) a.append a append adj[2:] adj 2: 2 s = [None] s [None] None for i in range(1, n + 1):
    s.append([False, i])
     i range(1, n + 1) range 1 n + 1 n 1 s.append([False, i]) s.append s append [False, i] False i time = 0 time 0 def dfs(u):
    global time
    s[u][0] = True
    time += 1
    s[u].append(time)
    
    for v in a[u]:
        if s[v][0] == False:
            dfs(v)
            
    time += 1
    s[u].append(time)
     dfs global time s[u][0] = True s[u][0] [u] s u 0 True time += 1 time 1 s[u].append(time) [u].append [u] s u append time for v in a[u]:
        if s[v][0] == False:
            dfs(v)
            
     v a[u] a u if s[v][0] == False:
            dfs(v)
            
     s[v][0] == False s[v][0] [v] s v 0 False dfs(v) dfs v time += 1 time 1 s[u].append(time) [u].append [u] s u append time u u for i in range(1,n+1):
    if s[i][0] == False:
        dfs(i)
         i range(1,n+1) range 1 n+1 n 1 if s[i][0] == False:
        dfs(i)
         s[i][0] == False s[i][0] [i] s i 0 False dfs(i) dfs i for x in s[1:]:
    print(*x[1:]) x s[1:] s 1: 1 print(*x[1:]) print *x[1:] x[1:] x 1: 1 time = 0 0 time n = int(input()) int(input()) n s = [None] [None] s adj = list(map(int,input().split())) list(map(int,input().split())) adj def dfs(u):
    global time
    s[u][0] = True
    time += 1
    s[u].append(time)
    
    for v in a[u]:
        if s[v][0] == False:
            dfs(v)
            
    time += 1
    s[u].append(time)
     def dfs(u):
    global time
    s[u][0] = True
    time += 1
    s[u].append(time)
    
    for v in a[u]:
        if s[v][0] == False:
            dfs(v)
            
    time += 1
    s[u].append(time)
     dfs a = [None] [None] a
n = int(input())
a = [None]
for i in range(n):
    adj = list(map(int,input().split()))
    a.append(adj[2:])
    
s = [None]
for i in range(1, n + 1):
    s.append([False, i])
    
time = 0

def dfs(u):
    global time
    s[u][0] = True
    time += 1
    s[u].append(time)
    
    for v in a[u]:
        if s[v][0] == False:
            dfs(v)
            
    time += 1
    s[u].append(time)
    
for i in range(1,n+1):
    if s[i][0] == False:
        dfs(i)
        
for x in s[1:]:
    print(*x[1:])
