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