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