import sys

def DFS(index, tm, l, a, b):
 tm += 1
 a[index] = tm
 for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
 tm += 1
 b[index] = tm
 return tm


n = input()
l=[]
for i in xrange(n):
 l.append([int(s) for s in sys.stdin.readline().split()[2:]])
a = [0] * n
b = [0] * n
tm = 0
for i in xrange(n):
 if not a[i]:
    tm = DFS(i, tm, l, a, b)

for i in xrange(n):
   print i+1, a[i], b[i] import sys sys def DFS(index, tm, l, a, b):
 tm += 1
 a[index] = tm
 for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
 tm += 1
 b[index] = tm
 return tm DFS tm += 1 tm 1 a[index] = tm a[index] a index tm for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
  i l[index] l index if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
  not a[i-1] a[i-1] a i-1 i 1 tm = DFS(i-1, tm, l, a, b) tm DFS(i-1, tm, l, a, b) DFS i-1 i 1 tm l a b tm += 1 tm 1 b[index] = tm b[index] b index tm return tm tm index index tm tm l l a a b b n = input() n input() input l=[] l [] for i in xrange(n):
 l.append([int(s) for s in sys.stdin.readline().split()[2:]]) i xrange(n) xrange 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 tm = 0 tm 0 for i in xrange(n):
 if not a[i]:
    tm = DFS(i, tm, l, a, b) i xrange(n) xrange n if not a[i]:
    tm = DFS(i, tm, l, a, b) not a[i] a[i] a i tm = DFS(i, tm, l, a, b) tm DFS(i, tm, l, a, b) DFS i tm 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 def DFS(index, tm, l, a, b):
 tm += 1
 a[index] = tm
 for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
 tm += 1
 b[index] = tm
 return tm def DFS(index, tm, l, a, b):
 tm += 1
 a[index] = tm
 for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
 tm += 1
 b[index] = tm
 return tm DFS n = input() input() n a = [0] * n [0] * n a tm = 0 0 tm b = [0] * n [0] * n b l=[] [] l tm = DFS(i, tm, l, a, b) DFS(i, tm, l, a, b) tm
import sys

def DFS(index, tm, l, a, b):
 tm += 1
 a[index] = tm
 for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
 tm += 1
 b[index] = tm
 return tm


n = input()
l=[]
for i in xrange(n):
 l.append([int(s) for s in sys.stdin.readline().split()[2:]])
a = [0] * n
b = [0] * n
tm = 0
for i in xrange(n):
 if not a[i]:
    tm = DFS(i, tm, l, a, b)

for i in xrange(n):
   print i+1, a[i], b[i]