n=int(input())
D=[0]*(n+1)
F=[0]*(n+1)
v=[[] for i in range(n+1)]
flg=True
t=1
for i in range(n):
  a=list(map(int,input().split()))
  v[a[0]]=sorted(a[2:])

def dfs(p):
  global t
  if D[p]!=0: return
  D[p]=t
  t+=1
  for i in v[p]:
    if D[i]==0: dfs(i)
  F[p]=t
  t+=1

while flg:
  flg=False
  for i in range(1,n+1):
    if D[i]==0:
      flg=True
      dfs(i)

for i in range(1,n+1):
  print(f'{i} {D[i]} {F[i]}') n=int(input()) n int(input()) int input() input D=[0]*(n+1) D [0]*(n+1) [0] 0 n+1 n 1 F=[0]*(n+1) F [0]*(n+1) [0] 0 n+1 n 1 [] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [] v=[[] for i in range(n+1)] v [[] for i in range(n+1)] flg=True flg True t=1 t 1 for i in range(n):
  a=list(map(int,input().split()))
  v[a[0]]=sorted(a[2:]) i range(n) range n a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split v[a[0]]=sorted(a[2:]) v[a[0]] v a[0] a 0 sorted(a[2:]) sorted a[2:] a 2: 2 def dfs(p):
  global t
  if D[p]!=0: return
  D[p]=t
  t+=1
  for i in v[p]:
    if D[i]==0: dfs(i)
  F[p]=t
  t+=1 dfs global t if D[p]!=0: return
   D[p]!=0 D[p] D p 0 D[p]=t D[p] D p t t+=1 t 1 for i in v[p]:
    if D[i]==0: dfs(i)
   i v[p] v p if D[i]==0: dfs(i)
   D[i]==0 D[i] D i 0 F[p]=t F[p] F p t t+=1 t 1 p p while flg:
  flg=False
  for i in range(1,n+1):
    if D[i]==0:
      flg=True
      dfs(i) flg flg=False flg False for i in range(1,n+1):
    if D[i]==0:
      flg=True
      dfs(i) i range(1,n+1) range 1 n+1 n 1 if D[i]==0:
      flg=True
      dfs(i) D[i]==0 D[i] D i 0 flg=True flg True dfs(i) dfs i for i in range(1,n+1):
  print(f'{i} {D[i]} {F[i]}') i range(1,n+1) range 1 n+1 n 1 print(f'{i} {D[i]} {F[i]}') print f'{i} {D[i]} {F[i]}' n=int(input()) int(input()) n flg=False False flg flg=True True flg D=[0]*(n+1) [0]*(n+1) D flg=True True flg F=[0]*(n+1) [0]*(n+1) F t=1 1 t a=list(map(int,input().split())) list(map(int,input().split())) a v=[[] for i in range(n+1)] [[] for i in range(n+1)] v def dfs(p):
  global t
  if D[p]!=0: return
  D[p]=t
  t+=1
  for i in v[p]:
    if D[i]==0: dfs(i)
  F[p]=t
  t+=1 def dfs(p):
  global t
  if D[p]!=0: return
  D[p]=t
  t+=1
  for i in v[p]:
    if D[i]==0: dfs(i)
  F[p]=t
  t+=1 dfs
n=int(input())
D=[0]*(n+1)
F=[0]*(n+1)
v=[[] for i in range(n+1)]
flg=True
t=1
for i in range(n):
  a=list(map(int,input().split()))
  v[a[0]]=sorted(a[2:])

def dfs(p):
  global t
  if D[p]!=0: return
  D[p]=t
  t+=1
  for i in v[p]:
    if D[i]==0: dfs(i)
  F[p]=t
  t+=1

while flg:
  flg=False
  for i in range(1,n+1):
    if D[i]==0:
      flg=True
      dfs(i)

for i in range(1,n+1):
  print(f'{i} {D[i]} {F[i]}')
