import sys
  
def dfs(i, t, l, a, b):
   t += 1
   a[i] = t
   for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
   t += 1
   b[i] = t
   return t
  
  
n = input()
l=[]
for i in range(n):
   l.append([int(s) for s in sys.stdin.readline().split()[2:]])
a = [0] * n
b = [0] * n
t = 0
for i in xrange(n):
   if not a[i]:
      t = dfs(i, t, l, a, b)
  
for i in xrange(n):
   print i+1, a[i], b[i]  import sys sys def dfs(i, t, l, a, b):
   t += 1
   a[i] = t
   for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
   t += 1
   b[i] = t
   return t
  
   dfs t += 1 t 1 a[i] = t a[i] a i t for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
    j l[i] l i if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
    not a[j-1] a[j-1] a j-1 j 1 t = dfs(j-1, t, l, a, b) t dfs(j-1, t, l, a, b) dfs j-1 j 1 t l a b t += 1 t 1 b[i] = t b[i] b i t return t t i i t t l l a a b b n = input() n input() input l=[] l [] for i in range(n):
   l.append([int(s) for s in sys.stdin.readline().split()[2:]]) i range(n) range n int(s) for s in sys.stdin.readline().split()[2:] for s in sys.stdin.readline().split()[2:] s sys.stdin.readline().split()[2:] sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split 2: 2 for s in sys.stdin.readline().split()[2:] int(s) int s l.append([int(s) for s in sys.stdin.readline().split()[2:]]) l.append l append [int(s) for s in sys.stdin.readline().split()[2:]] a = [0] * n a [0] * n [0] 0 n b = [0] * n b [0] * n [0] 0 n t = 0 t 0 for i in xrange(n):
   if not a[i]:
      t = dfs(i, t, l, a, b)
   i xrange(n) xrange n if not a[i]:
      t = dfs(i, t, l, a, b)
   not a[i] a[i] a i t = dfs(i, t, l, a, b) t dfs(i, t, l, a, b) dfs i t l a b for i in xrange(n):
   print i+1, a[i], b[i]  i xrange(n) xrange n print i+1 i 1 a[i] a i b[i] b i t = dfs(i, t, l, a, b) dfs(i, t, l, a, b) t def dfs(i, t, l, a, b):
   t += 1
   a[i] = t
   for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
   t += 1
   b[i] = t
   return t
  
   def dfs(i, t, l, a, b):
   t += 1
   a[i] = t
   for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
   t += 1
   b[i] = t
   return t
  
   dfs n = input() input() n t = 0 0 t b = [0] * n [0] * n b a = [0] * n [0] * n a l=[] [] l
import sys
  
def dfs(i, t, l, a, b):
   t += 1
   a[i] = t
   for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
   t += 1
   b[i] = t
   return t
  
  
n = input()
l=[]
for i in range(n):
   l.append([int(s) for s in sys.stdin.readline().split()[2:]])
a = [0] * n
b = [0] * n
t = 0
for i in xrange(n):
   if not a[i]:
      t = dfs(i, t, l, a, b)
  
for i in xrange(n):
   print i+1, a[i], b[i] 