# coding: UTF-8
from collections import deque
#入力値の整理
n = int(input())
adj={}
visited={}
d={}
f={}
t=0
visited=set()
for i in range(n):
  raw=list(map(int,input().split()))
  u = raw.pop(0)
  k = raw.pop(0)
  raw.sort()
  q = deque(raw)
  adj[u] = q  
  d[u] = -1
  f[u] = -1

next = 1
v = next
d[next] = t + 1
stack = deque()
visited.add(v)

while True:
  t = t+1
  clear = True
  while adj[v]:
    cand = adj[v].popleft()
    if cand not in visited:
      next = cand
      d[next] = t + 1
      visited.add(next)
      clear = False
      break
  if clear:
    f[v] = t + 1
    if stack:
      next = stack.pop()
      v = next
    else:
      end = True
      for i in range(n):
        if i+1 not in visited:
          next = i+1
          end = False
          break
      if end:
        break
      else:
        t = t+1
        v = next
        d[next] = t + 1
        visited.add(v)
  else:
    stack.append(v)
    v = next

#print
i = 0
for j in range(n):
  i += 1
  print(str(i) + " " + str(d[i]) + " " + str(f[i]))

#return d,f
 from collections import deque n = int(input()) n int(input()) int input() input adj={} adj {} visited={} visited {} d={} d {} f={} f {} t=0 t 0 visited=set() visited set() set for i in range(n):
  raw=list(map(int,input().split()))
  u = raw.pop(0)
  k = raw.pop(0)
  raw.sort()
  q = deque(raw)
  adj[u] = q  
  d[u] = -1
  f[u] = -1 i range(n) range n raw=list(map(int,input().split())) raw list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split u = raw.pop(0) u raw.pop(0) raw.pop raw pop 0 k = raw.pop(0) k raw.pop(0) raw.pop raw pop 0 raw.sort() raw.sort raw sort q = deque(raw) q deque(raw) deque raw adj[u] = q adj[u] adj u q d[u] = -1 d[u] d u -1 f[u] = -1 f[u] f u -1 next = 1 next 1 v = next v next d[next] = t + 1 d[next] d next t + 1 t 1 stack = deque() stack deque() deque visited.add(v) visited.add visited add v while True:
  t = t+1
  clear = True
  while adj[v]:
    cand = adj[v].popleft()
    if cand not in visited:
      next = cand
      d[next] = t + 1
      visited.add(next)
      clear = False
      break
  if clear:
    f[v] = t + 1
    if stack:
      next = stack.pop()
      v = next
    else:
      end = True
      for i in range(n):
        if i+1 not in visited:
          next = i+1
          end = False
          break
      if end:
        break
      else:
        t = t+1
        v = next
        d[next] = t + 1
        visited.add(v)
  else:
    stack.append(v)
    v = next

#print True t = t+1 t t+1 t 1 clear = True clear True while adj[v]:
    cand = adj[v].popleft()
    if cand not in visited:
      next = cand
      d[next] = t + 1
      visited.add(next)
      clear = False
      break
   adj[v] adj v cand = adj[v].popleft() cand adj[v].popleft() [v].popleft [v] adj v popleft if cand not in visited:
      next = cand
      d[next] = t + 1
      visited.add(next)
      clear = False
      break
   cand not in visited cand visited next = cand next cand d[next] = t + 1 d[next] d next t + 1 t 1 visited.add(next) visited.add visited add next clear = False clear False break if clear:
    f[v] = t + 1
    if stack:
      next = stack.pop()
      v = next
    else:
      end = True
      for i in range(n):
        if i+1 not in visited:
          next = i+1
          end = False
          break
      if end:
        break
      else:
        t = t+1
        v = next
        d[next] = t + 1
        visited.add(v)
  else:
    stack.append(v)
    v = next

#print clear f[v] = t + 1 f[v] f v t + 1 t 1 if stack:
      next = stack.pop()
      v = next
    else:
      end = True
      for i in range(n):
        if i+1 not in visited:
          next = i+1
          end = False
          break
      if end:
        break
      else:
        t = t+1
        v = next
        d[next] = t + 1
        visited.add(v)
   stack next = stack.pop() next stack.pop() stack.pop stack pop v = next v next end = True end True for i in range(n):
        if i+1 not in visited:
          next = i+1
          end = False
          break
       i range(n) range n if i+1 not in visited:
          next = i+1
          end = False
          break
       i+1 not in visited i+1 i 1 visited next = i+1 next i+1 i 1 end = False end False break if end:
        break
      else:
        t = t+1
        v = next
        d[next] = t + 1
        visited.add(v)
   end break t = t+1 t t+1 t 1 v = next v next d[next] = t + 1 d[next] d next t + 1 t 1 visited.add(v) visited.add visited add v stack.append(v) stack.append stack append v v = next v next i = 0 i 0 for j in range(n):
  i += 1
  print(str(i) + " " + str(d[i]) + " " + str(f[i]))

#return d,f j range(n) range n i += 1 i 1 print(str(i) + " " + str(d[i]) + " " + str(f[i])) print str(i) + " " + str(d[i]) + " " + str(f[i]) str(i) + " " + str(d[i]) + " " str(i) + " " + str(d[i]) str(i) + " " str(i) str i " " str(d[i]) str d[i] d i " " str(f[i]) str f[i] f i t = t+1 t+1 t n = int(input()) int(input()) n next = i+1 i+1 next visited={} {} visited next = cand cand next q = deque(raw) deque(raw) q t=0 0 t end = True True end stack = deque() deque() stack f={} {} f i += 1 1 i d={} {} d end = False False end t = t+1 t+1 t v = next next v v = next next v next = 1 1 next v = next next v visited=set() set() visited raw=list(map(int,input().split())) list(map(int,input().split())) raw adj={} {} adj k = raw.pop(0) raw.pop(0) k clear = False False clear cand = adj[v].popleft() adj[v].popleft() cand v = next next v u = raw.pop(0) raw.pop(0) u i = 0 0 i clear = True True clear next = stack.pop() stack.pop() next
# coding: UTF-8
from collections import deque
#入力値の整理
n = int(input())
adj={}
visited={}
d={}
f={}
t=0
visited=set()
for i in range(n):
  raw=list(map(int,input().split()))
  u = raw.pop(0)
  k = raw.pop(0)
  raw.sort()
  q = deque(raw)
  adj[u] = q  
  d[u] = -1
  f[u] = -1

next = 1
v = next
d[next] = t + 1
stack = deque()
visited.add(v)

while True:
  t = t+1
  clear = True
  while adj[v]:
    cand = adj[v].popleft()
    if cand not in visited:
      next = cand
      d[next] = t + 1
      visited.add(next)
      clear = False
      break
  if clear:
    f[v] = t + 1
    if stack:
      next = stack.pop()
      v = next
    else:
      end = True
      for i in range(n):
        if i+1 not in visited:
          next = i+1
          end = False
          break
      if end:
        break
      else:
        t = t+1
        v = next
        d[next] = t + 1
        visited.add(v)
  else:
    stack.append(v)
    v = next

#print
i = 0
for j in range(n):
  i += 1
  print(str(i) + " " + str(d[i]) + " " + str(f[i]))

#return d,f

