n = int(input())
g = [[]for i in range(n)]
for i in range(n):
    v = list(map(int,input().split()))
    u = v[0]-1
    k = v[1]
    for j in range(k):
        g[u].append(v[j+2]-1)
time = 1
ans = []
d = [0]*n
f = [0] *n
visited = [0]*n

def dfs(now,last = -1):
    global time
    
    visited[now] = 1
    d[now] = time
    time += 1
    for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
    f[now] = time
    time +=1
    
for i in range(n):
    if not visited[i]:dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])
    
    
        
         n = int(input()) n int(input()) int input() input []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):
    v = list(map(int,input().split()))
    u = v[0]-1
    k = v[1]
    for j in range(k):
        g[u].append(v[j+2]-1) i range(n) range n v = list(map(int,input().split())) v list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split u = v[0]-1 u v[0]-1 v[0] v 0 1 k = v[1] k v[1] v 1 for j in range(k):
        g[u].append(v[j+2]-1) j range(k) range k g[u].append(v[j+2]-1) [u].append [u] g u append v[j+2]-1 v[j+2] v j+2 j 2 1 time = 1 time 1 ans = [] ans [] d = [0]*n d [0]*n [0] 0 n f = [0] *n f [0] *n [0] 0 n visited = [0]*n visited [0]*n [0] 0 n def dfs(now,last = -1):
    global time
    
    visited[now] = 1
    d[now] = time
    time += 1
    for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
    f[now] = time
    time +=1
     dfs global time visited[now] = 1 visited[now] visited now 1 d[now] = time d[now] d now time time += 1 time 1 for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
     next g[now] g now if visited[next]:continue
         visited[next] visited next dfs(next,now) dfs next now f[now] = time f[now] f now time time +=1 time 1 now now last = -1 last -1 for i in range(n):
    if not visited[i]:dfs(i) i range(n) range n if not visited[i]:df not visited[i] visited[i] visited i for i in range(n):
    print(i+1,d[i],f[i])
    
    
        
         i range(n) range n print(i+1,d[i],f[i]) print i+1 i 1 d[i] d i f[i] f i k = v[1] v[1] k v = list(map(int,input().split())) list(map(int,input().split())) v n = int(input()) int(input()) n d = [0]*n [0]*n d u = v[0]-1 v[0]-1 u ans = [] [] ans f = [0] *n [0] *n f g = [[]for i in range(n)] [[]for i in range(n)] g time = 1 1 time visited = [0]*n [0]*n visited def dfs(now,last = -1):
    global time
    
    visited[now] = 1
    d[now] = time
    time += 1
    for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
    f[now] = time
    time +=1
     def dfs(now,last = -1):
    global time
    
    visited[now] = 1
    d[now] = time
    time += 1
    for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
    f[now] = time
    time +=1
     dfs
n = int(input())
g = [[]for i in range(n)]
for i in range(n):
    v = list(map(int,input().split()))
    u = v[0]-1
    k = v[1]
    for j in range(k):
        g[u].append(v[j+2]-1)
time = 1
ans = []
d = [0]*n
f = [0] *n
visited = [0]*n

def dfs(now,last = -1):
    global time
    
    visited[now] = 1
    d[now] = time
    time += 1
    for next in g[now]:
        if visited[next]:continue
        dfs(next,now)
    f[now] = time
    time +=1
    
for i in range(n):
    if not visited[i]:dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])
    
    
        
        
