from collections import deque

def dfs(v):
    global t
    
    d[v] = t
    visited[v] = True
    t += 1
    
    for u in graph[v]:
        if not visited[u]: dfs(u)
    f[v] = t
    t += 1
    
    
n = int(input())
graph = [deque() for i in range(n)]

visited = [False] * n
d = [0] * n
f = [0] * n
t = 1

for i in range(n):
    nums = list(map(int, input().split()))
    for j in nums[2:]:
        graph[i].append(j-1)
         
for i in range(n):
    if not visited[i]: dfs(i)

for idx, df in enumerate(zip(d, f)):
    print(idx+1, df[0], df[1])
 from collections import deque def dfs(v):
    global t
    
    d[v] = t
    visited[v] = True
    t += 1
    
    for u in graph[v]:
        if not visited[u]: dfs(u)
    f[v] = t
    t += 1
    
     dfs global t d[v] = t d[v] d v t visited[v] = True visited[v] visited v True t += 1 t 1 for u in graph[v]:
        if not visited[u]: dfs(u)
     u graph[v] graph v if not visited[u]: dfs(u)
     not visited[u] visited[u] visited u f[v] = t f[v] f v t t += 1 t 1 v v n = int(input()) n int(input()) int input() input deque() for i in range(n) for i in range(n) i range(n) range n for i in range(n) deque() deque graph = [deque() for i in range(n)] graph [deque() for i in range(n)] visited = [False] * n visited [False] * n [False] False n d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n t = 1 t 1 for i in range(n):
    nums = list(map(int, input().split()))
    for j in nums[2:]:
        graph[i].append(j-1)
          i range(n) range n nums = list(map(int, input().split())) nums list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for j in nums[2:]:
        graph[i].append(j-1)
          j nums[2:] nums 2: 2 graph[i].append(j-1) [i].append [i] graph i append j-1 j 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 idx, df in enumerate(zip(d, f)):
    print(idx+1, df[0], df[1]) idx df enumerate(zip(d, f)) enumerate zip(d, f) zip d f print(idx+1, df[0], df[1]) print idx+1 idx 1 df[0] df 0 df[1] df 1 nums = list(map(int, input().split())) list(map(int, input().split())) nums t = 1 1 t n = int(input()) int(input()) n f = [0] * n [0] * n f def dfs(v):
    global t
    
    d[v] = t
    visited[v] = True
    t += 1
    
    for u in graph[v]:
        if not visited[u]: dfs(u)
    f[v] = t
    t += 1
    
     def dfs(v):
    global t
    
    d[v] = t
    visited[v] = True
    t += 1
    
    for u in graph[v]:
        if not visited[u]: dfs(u)
    f[v] = t
    t += 1
    
     dfs d = [0] * n [0] * n d visited = [False] * n [False] * n visited graph = [deque() for i in range(n)] [deque() for i in range(n)] graph
from collections import deque

def dfs(v):
    global t
    
    d[v] = t
    visited[v] = True
    t += 1
    
    for u in graph[v]:
        if not visited[u]: dfs(u)
    f[v] = t
    t += 1
    
    
n = int(input())
graph = [deque() for i in range(n)]

visited = [False] * n
d = [0] * n
f = [0] * n
t = 1

for i in range(n):
    nums = list(map(int, input().split()))
    for j in nums[2:]:
        graph[i].append(j-1)
         
for i in range(n):
    if not visited[i]: dfs(i)

for idx, df in enumerate(zip(d, f)):
    print(idx+1, df[0], df[1])

