n = int(input())
u = [list(map(int,input().split())) for _ in range(n)]
ts = [[0,0] for _ in range(n)]
time = 0

def dfs(i):
  global time
  ts[i][0] = time
  for j in range(u[i][1]):
    a = u[i][j+2]-1
    if ts[a][0] == 0:
      time += 1
      dfs(a)
  time += 1
  ts[i][1] = time
  
for i in range(n):
  if ts[i][0] == 0:
    time += 1
    dfs(i)
  
for i in range(n):
  print(i+1, ts[i][0], ts[i][1]) n = int(input()) n int(input()) int input() input list(map(int,input().split())) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split u = [list(map(int,input().split())) for _ in range(n)] u [list(map(int,input().split())) for _ in range(n)] [0,0] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0,0] 0 0 ts = [[0,0] for _ in range(n)] ts [[0,0] for _ in range(n)] time = 0 time 0 def dfs(i):
  global time
  ts[i][0] = time
  for j in range(u[i][1]):
    a = u[i][j+2]-1
    if ts[a][0] == 0:
      time += 1
      dfs(a)
  time += 1
  ts[i][1] = time
   dfs global time ts[i][0] = time ts[i][0] [i] ts i 0 time for j in range(u[i][1]):
    a = u[i][j+2]-1
    if ts[a][0] == 0:
      time += 1
      dfs(a)
   j range(u[i][1]) range u[i][1] [i] u i 1 a = u[i][j+2]-1 a u[i][j+2]-1 u[i][j+2] [i] u i j+2 j 2 1 if ts[a][0] == 0:
      time += 1
      dfs(a)
   ts[a][0] == 0 ts[a][0] [a] ts a 0 0 time += 1 time 1 dfs(a) dfs a time += 1 time 1 ts[i][1] = time ts[i][1] [i] ts i 1 time i i for i in range(n):
  if ts[i][0] == 0:
    time += 1
    dfs(i)
   i range(n) range n if ts[i][0] == 0:
    time += 1
    dfs(i)
   ts[i][0] == 0 ts[i][0] [i] ts i 0 0 time += 1 time 1 dfs(i) dfs i for i in range(n):
  print(i+1, ts[i][0], ts[i][1]) i range(n) range n print(i+1, ts[i][0], ts[i][1]) print i+1 i 1 ts[i][0] [i] ts i 0 ts[i][1] [i] ts i 1 def dfs(i):
  global time
  ts[i][0] = time
  for j in range(u[i][1]):
    a = u[i][j+2]-1
    if ts[a][0] == 0:
      time += 1
      dfs(a)
  time += 1
  ts[i][1] = time
   def dfs(i):
  global time
  ts[i][0] = time
  for j in range(u[i][1]):
    a = u[i][j+2]-1
    if ts[a][0] == 0:
      time += 1
      dfs(a)
  time += 1
  ts[i][1] = time
   dfs u = [list(map(int,input().split())) for _ in range(n)] [list(map(int,input().split())) for _ in range(n)] u ts = [[0,0] for _ in range(n)] [[0,0] for _ in range(n)] ts time += 1 1 time time = 0 0 time n = int(input()) int(input()) n
n = int(input())
u = [list(map(int,input().split())) for _ in range(n)]
ts = [[0,0] for _ in range(n)]
time = 0

def dfs(i):
  global time
  ts[i][0] = time
  for j in range(u[i][1]):
    a = u[i][j+2]-1
    if ts[a][0] == 0:
      time += 1
      dfs(a)
  time += 1
  ts[i][1] = time
  
for i in range(n):
  if ts[i][0] == 0:
    time += 1
    dfs(i)
  
for i in range(n):
  print(i+1, ts[i][0], ts[i][1])
