n = int(input())
graph = [[] for _ in range(n)]

global time
global visited 
global f_time 
global e_time 

time = 1
visited = [0 for _ in range(n)]
f_time = [0 for _ in range(n)]
e_time = [0 for _ in range(n)]

def input_graph(n):
  for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1)

def dfs(node_id):
  global time
  f_time[node_id] = time
  time += 1

  for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

  e_time[node_id] = time
  time += 1



if __name__ == "__main__":
  input_graph(n)
  for i in range(n):
    if visited[i] == 1:
      continue
    visited[i] = 1
    dfs(i)

  for i, (f, e) in enumerate(zip(f_time, e_time)):
    print(i+1, f, e)
  
   n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] global time global visited global f_time global e_time time = 1 time 1 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 visited = [0 for _ in range(n)] visited [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 f_time = [0 for _ in range(n)] f_time [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 e_time = [0 for _ in range(n)] e_time [0 for _ in range(n)] def input_graph(n):
  for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1) input_graph for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1) _ range(n) range n node_id, num, *v = list(map(int, input().split())) node_id list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split num *v v for i in range(num):
      graph[node_id-1].append(v[i]-1) i range(num) range num graph[node_id-1].append(v[i]-1) [node_id-1].append [node_id-1] graph node_id-1 node_id 1 append v[i]-1 v[i] v i 1 n n def dfs(node_id):
  global time
  f_time[node_id] = time
  time += 1

  for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

  e_time[node_id] = time
  time += 1 dfs global time f_time[node_id] = time f_time[node_id] f_time node_id time time += 1 time 1 for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

   ad_node graph[node_id] graph node_id if visited[ad_node] == 1:
      continue
     visited[ad_node] == 1 visited[ad_node] visited ad_node 1 continue visited[ad_node] = 1 visited[ad_node] visited ad_node 1 dfs(ad_node) dfs ad_node e_time[node_id] = time e_time[node_id] e_time node_id time time += 1 time 1 node_id node_id if __name__ == "__main__":
  input_graph(n)
  for i in range(n):
    if visited[i] == 1:
      continue
    visited[i] = 1
    dfs(i)

  for i, (f, e) in enumerate(zip(f_time, e_time)):
    print(i+1, f, e)
  
   __name__ == "__main__" __name__ "__main__" input_graph(n) input_graph n for i in range(n):
    if visited[i] == 1:
      continue
    visited[i] = 1
    dfs(i)

   i range(n) range n if visited[i] == 1:
      continue
     visited[i] == 1 visited[i] visited i 1 continue visited[i] = 1 visited[i] visited i 1 dfs(i) dfs i for i, (f, e) in enumerate(zip(f_time, e_time)):
    print(i+1, f, e)
  
   i (f, e) f e enumerate(zip(f_time, e_time)) enumerate zip(f_time, e_time) zip f_time e_time print(i+1, f, e) print i+1 i 1 f e graph = [[] for _ in range(n)] [[] for _ in range(n)] graph global time def input_graph(n):
  for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1) def input_graph(n):
  for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1) input_graph n = int(input()) int(input()) n global f_time visited = [0 for _ in range(n)] [0 for _ in range(n)] visited def dfs(node_id):
  global time
  f_time[node_id] = time
  time += 1

  for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

  e_time[node_id] = time
  time += 1 def dfs(node_id):
  global time
  f_time[node_id] = time
  time += 1

  for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

  e_time[node_id] = time
  time += 1 dfs global visited f_time = [0 for _ in range(n)] [0 for _ in range(n)] f_time e_time = [0 for _ in range(n)] [0 for _ in range(n)] e_time time = 1 1 time global e_time
n = int(input())
graph = [[] for _ in range(n)]

global time
global visited 
global f_time 
global e_time 

time = 1
visited = [0 for _ in range(n)]
f_time = [0 for _ in range(n)]
e_time = [0 for _ in range(n)]

def input_graph(n):
  for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1)

def dfs(node_id):
  global time
  f_time[node_id] = time
  time += 1

  for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

  e_time[node_id] = time
  time += 1



if __name__ == "__main__":
  input_graph(n)
  for i in range(n):
    if visited[i] == 1:
      continue
    visited[i] = 1
    dfs(i)

  for i, (f, e) in enumerate(zip(f_time, e_time)):
    print(i+1, f, e)
  
  
