n = int(raw_input())
  
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
g = [0 for i in range(n)]
  
  
def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
      
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
  
def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
  
for i in range(n):
    g = map(int, raw_input().split())
    for j in range(g[1]):
        a[g[0]-1][g[2+j]-1] = 1
  
main() n = int(raw_input()) n int(raw_input()) int raw_input() raw_input 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] a [[0 for i in range(n)] for j in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 st = [0 for i in range(n)] st [0 for i in range(n)] time = [0] time [0] 0 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 g = [0 for i in range(n)] g [0 for i in range(n)] def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
      
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
   dfs_visit st[s] = 1 st[s] st s 1 time[0] += 1 time[0] time 0 1 d[s] = time[0] d[s] d s time[0] time 0 for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
     k range(n) range n if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
     a[s][k] == 1 and st[k] == 0 a[s][k] == 1 a[s][k] [s] a s k 1 st[k] == 0 st[k] st k 0 dfs_visit(k) dfs_visit k st[s] ==2 st[s] st s 2 time[0] += 1 time[0] time 0 1 f[s] = time[0] f[s] f s time[0] time 0 s s def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
   main for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
     s range(n) range n if st[s] == 0:
            dfs_visit(s)
     st[s] == 0 st[s] st s 0 dfs_visit(s) dfs_visit s for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
   s range(n) range n print '%d %d %d' %(s+1, d[s], f[s]) '%d %d %d' (s+1, d[s], f[s]) s+1 s 1 d[s] d s f[s] f s for i in range(n):
    g = map(int, raw_input().split())
    for j in range(g[1]):
        a[g[0]-1][g[2+j]-1] = 1
   i range(n) range n g = map(int, raw_input().split()) g map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(g[1]):
        a[g[0]-1][g[2+j]-1] = 1
   j range(g[1]) range g[1] g 1 a[g[0]-1][g[2+j]-1] = 1 a[g[0]-1][g[2+j]-1] [g[0]-1] a g[0]-1 g[0] g 0 1 g[2+j]-1 g[2+j] g 2+j 2 j 1 1 main() main n = int(raw_input()) int(raw_input()) n def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
      
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
   def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
      
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
   dfs_visit f = [0 for i in range(n)] [0 for i in range(n)] f time = [0] [0] time g = [0 for i in range(n)] [0 for i in range(n)] g d = [0 for i in range(n)] [0 for i in range(n)] d def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
   def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
   main g = map(int, raw_input().split()) map(int, raw_input().split()) g a = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] a st = [0 for i in range(n)] [0 for i in range(n)] st
n = int(raw_input())
  
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
g = [0 for i in range(n)]
  
  
def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
      
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
  
def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print '%d %d %d' %(s+1, d[s], f[s])
  
for i in range(n):
    g = map(int, raw_input().split())
    for j in range(g[1]):
        a[g[0]-1][g[2+j]-1] = 1
  
main()