from collections import defaultdict as dd

N = int(input())
graph = dd(list)
seen = dd(int)
u = []
d, f = dd(int), dd(int)
ts = 1
for _ in range(N):
  info = list(map(int, input().split()))
  u.append(info[0])
  graph[info[0]] = info[2:]

def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1

for key in u:
  if seen[key]:
    continue
  dfs(key)

for id in u:
  print("{} {} {}".format(id, d[id], f[id])) from collections import defaultdict as dd N = int(input()) N int(input()) int input() input graph = dd(list) graph dd(list) dd list seen = dd(int) seen dd(int) dd int u = [] u [] d, f = dd(int), dd(int) d dd(int) dd int f dd(int) dd int ts = 1 ts 1 for _ in range(N):
  info = list(map(int, input().split()))
  u.append(info[0])
  graph[info[0]] = info[2:] _ range(N) range N info = list(map(int, input().split())) info list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u.append(info[0]) u.append u append info[0] info 0 graph[info[0]] = info[2:] graph[info[0]] graph info[0] info 0 info[2:] info 2: 2 def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1 dfs global ts d[v] = ts d[v] d v ts ts += 1 ts 1 seen[v] = 1 seen[v] seen v 1 for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
   next_v graph[v] graph v if seen[next_v]:
      continue
     seen[next_v] seen next_v continue dfs(next_v) dfs next_v f[v] = ts f[v] f v ts ts += 1 ts 1 v v for key in u:
  if seen[key]:
    continue
  dfs(key) key u if seen[key]:
    continue
   seen[key] seen key continue dfs(key) dfs key for id in u:
  print("{} {} {}".format(id, d[id], f[id])) id u print("{} {} {}".format(id, d[id], f[id])) print "{} {} {}".format(id, d[id], f[id]) "{} {} {}".format "{} {} {}" format id d[id] d id f[id] f id def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1 def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1 dfs info = list(map(int, input().split())) list(map(int, input().split())) info d, f = dd(int), dd(int) dd(int) d f = dd(int), dd(int) dd(int) f ts = 1 1 ts u = [] [] u graph = dd(list) dd(list) graph N = int(input()) int(input()) N seen = dd(int) dd(int) seen
from collections import defaultdict as dd

N = int(input())
graph = dd(list)
seen = dd(int)
u = []
d, f = dd(int), dd(int)
ts = 1
for _ in range(N):
  info = list(map(int, input().split()))
  u.append(info[0])
  graph[info[0]] = info[2:]

def dfs(v):
  global ts
  d[v] = ts
  ts += 1
  
  seen[v] = 1
  for next_v in graph[v]:
    if seen[next_v]:
      continue
    dfs(next_v)
  
  f[v] = ts
  ts += 1

for key in u:
  if seen[key]:
    continue
  dfs(key)

for id in u:
  print("{} {} {}".format(id, d[id], f[id]))
