# coding: UTF-8
from collections import deque
n = int(input())
arrow = {}
visited = set()
d = {}
f = {}


for i in range(n):
  raw = list(map(int,input().split()))
  #print(raw)
  u = raw.pop(0)
  k = raw.pop(0)
  raw.sort()
  q = deque(raw)
  arrow[u] = q
  d[u] = -1
  f[u] = -1

def dfslocal(v,t,arrow,f,d):
  t += 1
  d[v] = t
  visited.add(v)
  #print("First visit to " + str(v) + " at " + str(t) + "!")
  while arrow[v]:
    k = arrow[v].popleft()
    if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
  f[v] = t+1
  return t+1

def dfsglobal(arrow,f,d):
  t = 0
  for u in range(n):
    if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
  return t

t = dfsglobal(arrow,f,d)

for i in range(n):
  print(str(i+1) + " " + str(d[i+1]) + " " + str(f[i+1])) from collections import deque n = int(input()) n int(input()) int input() input arrow = {} arrow {} visited = set() visited set() set d = {} d {} f = {} f {} for i in range(n):
  raw = list(map(int,input().split()))
  #print(raw)
  u = raw.pop(0)
  k = raw.pop(0)
  raw.sort()
  q = deque(raw)
  arrow[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 arrow[u] = q arrow[u] arrow u q d[u] = -1 d[u] d u -1 f[u] = -1 f[u] f u -1 def dfslocal(v,t,arrow,f,d):
  t += 1
  d[v] = t
  visited.add(v)
  #print("First visit to " + str(v) + " at " + str(t) + "!")
  while arrow[v]:
    k = arrow[v].popleft()
    if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
  f[v] = t+1
  return t+1 dfslocal t += 1 t 1 d[v] = t d[v] d v t visited.add(v) visited.add visited add v while arrow[v]:
    k = arrow[v].popleft()
    if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
   arrow[v] arrow v k = arrow[v].popleft() k arrow[v].popleft() [v].popleft [v] arrow v popleft if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
   k not in visited k visited t = dfslocal(k,t,arrow,f,d) t dfslocal(k,t,arrow,f,d) dfslocal k t arrow f d f[v] = t+1 f[v] f v t+1 t 1 return t+1 t+1 t 1 v v t t arrow arrow f f d d def dfsglobal(arrow,f,d):
  t = 0
  for u in range(n):
    if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
  return t dfsglobal t = 0 t 0 for u in range(n):
    if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
   u range(n) range n if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
   u+1 not in visited u+1 u 1 visited t = dfslocal(u+1,t,arrow,f,d) t dfslocal(u+1,t,arrow,f,d) dfslocal u+1 u 1 t arrow f d return t t arrow arrow f f d d t = dfsglobal(arrow,f,d) t dfsglobal(arrow,f,d) dfsglobal arrow f d for i in range(n):
  print(str(i+1) + " " + str(d[i+1]) + " " + str(f[i+1])) i range(n) range n print(str(i+1) + " " + str(d[i+1]) + " " + str(f[i+1])) print str(i+1) + " " + str(d[i+1]) + " " + str(f[i+1]) str(i+1) + " " + str(d[i+1]) + " " str(i+1) + " " + str(d[i+1]) str(i+1) + " " str(i+1) str i+1 i 1 " " str(d[i+1]) str d[i+1] d i+1 i 1 " " str(f[i+1]) str f[i+1] f i+1 i 1 d = {} {} d raw = list(map(int,input().split())) list(map(int,input().split())) raw arrow = {} {} arrow visited = set() set() visited k = raw.pop(0) raw.pop(0) k def dfsglobal(arrow,f,d):
  t = 0
  for u in range(n):
    if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
  return t def dfsglobal(arrow,f,d):
  t = 0
  for u in range(n):
    if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
  return t dfsglobal n = int(input()) int(input()) n def dfslocal(v,t,arrow,f,d):
  t += 1
  d[v] = t
  visited.add(v)
  #print("First visit to " + str(v) + " at " + str(t) + "!")
  while arrow[v]:
    k = arrow[v].popleft()
    if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
  f[v] = t+1
  return t+1 def dfslocal(v,t,arrow,f,d):
  t += 1
  d[v] = t
  visited.add(v)
  #print("First visit to " + str(v) + " at " + str(t) + "!")
  while arrow[v]:
    k = arrow[v].popleft()
    if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
  f[v] = t+1
  return t+1 dfslocal t = dfsglobal(arrow,f,d) dfsglobal(arrow,f,d) t f = {} {} f q = deque(raw) deque(raw) q u = raw.pop(0) raw.pop(0) u
# coding: UTF-8
from collections import deque
n = int(input())
arrow = {}
visited = set()
d = {}
f = {}


for i in range(n):
  raw = list(map(int,input().split()))
  #print(raw)
  u = raw.pop(0)
  k = raw.pop(0)
  raw.sort()
  q = deque(raw)
  arrow[u] = q
  d[u] = -1
  f[u] = -1

def dfslocal(v,t,arrow,f,d):
  t += 1
  d[v] = t
  visited.add(v)
  #print("First visit to " + str(v) + " at " + str(t) + "!")
  while arrow[v]:
    k = arrow[v].popleft()
    if k not in visited:
      
      t = dfslocal(k,t,arrow,f,d)
  f[v] = t+1
  return t+1

def dfsglobal(arrow,f,d):
  t = 0
  for u in range(n):
    if u+1 not in visited:
      t = dfslocal(u+1,t,arrow,f,d)
  return t

t = dfsglobal(arrow,f,d)

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