n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
col = [0 for i in range(n)]
t = [0]
 
def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
 
def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
     
for i in range(n):
    X = map(int, raw_input().split())
    for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
 
DFS() 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 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)] [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)] M = [[0 for i in range(n)] for j in range(n)] M [[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 col = [0 for i in range(n)] col [0 for i in range(n)] t = [0] t [0] 0 def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
  DFS_visit col[u] = 1 col[u] col u 1 t[0] += 1 t[0] t 0 1 d[u] = t[0] d[u] d u t[0] t 0 for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
     v range(n) range n if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
     M[u][v] == 1 and col[v] == 0 M[u][v] == 1 M[u][v] [u] M u v 1 col[v] == 0 col[v] col v 0 DFS_visit(v) DFS_visit v col[u] = 2 col[u] col u 2 t[0] += 1 t[0] t 0 1 f[u] = t[0] f[u] f u t[0] t 0 u u def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
      DFS for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
     u range(n) range n if col[u] == 0:
            DFS_visit(u)
     col[u] == 0 col[u] col u 0 DFS_visit(u) DFS_visit u for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
      u range(n) range n print '{0} {1} {2}'.format(u+1, d[u], f[u]) '{0} {1} {2}'.format '{0} {1} {2}' format u+1 u 1 d[u] d u f[u] f u for i in range(n):
    X = map(int, raw_input().split())
    for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
  i range(n) range n X = map(int, raw_input().split()) X map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
  j range(X[1]) range X[1] X 1 M[X[0]-1][X[2+j]-1] = 1 M[X[0]-1][X[2+j]-1] [X[0]-1] M X[0]-1 X[0] X 0 1 X[2+j]-1 X[2+j] X 2+j 2 j 1 1 DFS() DFS M = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] M f = [0 for i in range(n)] [0 for i in range(n)] f t = [0] [0] t def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
  def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
  DFS_visit G = [0 for i in range(n)] [0 for i in range(n)] G X = map(int, raw_input().split()) map(int, raw_input().split()) X def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
      def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
      DFS n = int(raw_input()) int(raw_input()) n d = [0 for i in range(n)] [0 for i in range(n)] d col = [0 for i in range(n)] [0 for i in range(n)] col
n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
col = [0 for i in range(n)]
t = [0]
 
def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
 
def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
     
for i in range(n):
    X = map(int, raw_input().split())
    for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
 
DFS()