def d(u):
 global t
 C[u]=0;t+=1;D[u]=t
 for v in R:
  if M[u][v]and C[v]:d(v)
 t+=1;F[u]=t
N=int(input());R=range(N)
M=[[0]*N for _ in R]
for e in[input().split()for _ in R]:
 for v in e[2:]:M[int(e[0])-1][int(v)-1]=1
C,D,F=[1]*N,[0]*N,[0]*N
t=0
for i in R:
 if C[i]:d(i)
for i in R:print(i+1,D[i],F[i]) def d(u):
 global t
 C[u]=0;t+=1;D[u]=t
 for v in R:
  if M[u][v]and C[v]:d(v)
 t+=1;F[u]=t d global t C[u]=0 C[u] C u 0 t+=1 t 1 D[u]=t D[u] D u t for v in R:
  if M[u][v]and C[v]:d(v)
  v R if M[u][v]and C[v]:d(v)
  M[u][v]and C[v] M[u][v] [u] M u v C[v] C v t+=1 t 1 F[u]=t F[u] F u t u u N=int(input()) N int(input()) int input() input R=range(N) R range(N) range N [0]*N for _ in R for _ in R _ R for _ in R [0]*N [0] 0 N M=[[0]*N for _ in R] M [[0]*N for _ in R] for e in[input().split()for _ in R]:
 for v in e[2:]:M[int(e[0])-1][int(v)-1]=1 e [input().split()for _ in R] for v in e[2:]:M[int(e[0])-1][int(v)-1]= v e[2:] e 2: 2 C,D,F=[1]*N,[0]*N,[0]*N C [1]*N [1] 1 N D [0]*N [0] 0 N F [0]*N [0] 0 N t=0 t 0 for i in R:
 if C[i]:d(i) i R if C[i]:d(i C[i] C i for i in R:print(i+1,D[i],F[i]) i R R=range(N) range(N) R t=0 0 t C,D,F=[1]*N,[0]*N,[0]*N [1]*N C def d(u):
 global t
 C[u]=0;t+=1;D[u]=t
 for v in R:
  if M[u][v]and C[v]:d(v)
 t+=1;F[u]=t def d(u):
 global t
 C[u]=0;t+=1;D[u]=t
 for v in R:
  if M[u][v]and C[v]:d(v)
 t+=1;F[u]=t d N=int(input()) int(input()) N F=[1]*N,[0]*N,[0]*N [0]*N F D,F=[1]*N,[0]*N,[0]*N [0]*N D M=[[0]*N for _ in R] [[0]*N for _ in R] M
def d(u):
 global t
 C[u]=0;t+=1;D[u]=t
 for v in R:
  if M[u][v]and C[v]:d(v)
 t+=1;F[u]=t
N=int(input());R=range(N)
M=[[0]*N for _ in R]
for e in[input().split()for _ in R]:
 for v in e[2:]:M[int(e[0])-1][int(v)-1]=1
C,D,F=[1]*N,[0]*N,[0]*N
t=0
for i in R:
 if C[i]:d(i)
for i in R:print(i+1,D[i],F[i])
