time=1
n=int(input())

A=[[] for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]

for i in range(n):
	a=list(map(int,input().split()))
	for j in range(a[1]):
		A[i].append(a[2+j]-1)

def dfs(q,num):
	global d,f,time
	d[num]=time
	for nx in q[num]:
		if d[nx]==0:
			time+=1
			dfs(q,nx)
	time+=1
	f[num]=time
	
for i in range(n):
	if d[i]==0:#unvisit
		dfs(A,i)
		time+=1

for i in range(n):
	print(i+1,d[i],f[i]) time=1 time 1 n=int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] A=[[] for i in range(n)] A [[] 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 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)] for i in range(n):
	a=list(map(int,input().split()))
	for j in range(a[1]):
		A[i].append(a[2+j]-1) i range(n) range n a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split for j in range(a[1]):
		A[i].append(a[2+j]-1) j range(a[1]) range a[1] a 1 A[i].append(a[2+j]-1) [i].append [i] A i append a[2+j]-1 a[2+j] a 2+j 2 j 1 def dfs(q,num):
	global d,f,time
	d[num]=time
	for nx in q[num]:
		if d[nx]==0:
			time+=1
			dfs(q,nx)
	time+=1
	f[num]=time
	 dfs global d,f,time d[num]=time d[num] d num time for nx in q[num]:
		if d[nx]==0:
			time+=1
			dfs(q,nx)
	 nx q[num] q num if d[nx]==0:
			time+=1
			dfs(q,nx)
	 d[nx]==0 d[nx] d nx 0 time+=1 time 1 dfs(q,nx) dfs q nx time+=1 time 1 f[num]=time f[num] f num time q q num num for i in range(n):
	if d[i]==0:#unvisit
		dfs(A,i)
		time+=1 i range(n) range n if d[i]==0:#unvisit
		dfs(A,i)
		time+=1 d[i]==0 d[i] d i 0 dfs(A,i) dfs A i time+=1 time 1 for i in range(n):
	print(i+1,d[i],f[i]) i range(n) range n print(i+1,d[i],f[i]) print i+1 i 1 d[i] d i f[i] f i time=1 1 time n=int(input()) int(input()) n f=[0 for i in range(n)] [0 for i in range(n)] f a=list(map(int,input().split())) list(map(int,input().split())) a time+=1 1 time def dfs(q,num):
	global d,f,time
	d[num]=time
	for nx in q[num]:
		if d[nx]==0:
			time+=1
			dfs(q,nx)
	time+=1
	f[num]=time
	 def dfs(q,num):
	global d,f,time
	d[num]=time
	for nx in q[num]:
		if d[nx]==0:
			time+=1
			dfs(q,nx)
	time+=1
	f[num]=time
	 dfs d=[0 for i in range(n)] [0 for i in range(n)] d A=[[] for i in range(n)] [[] for i in range(n)] A
time=1
n=int(input())

A=[[] for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]

for i in range(n):
	a=list(map(int,input().split()))
	for j in range(a[1]):
		A[i].append(a[2+j]-1)

def dfs(q,num):
	global d,f,time
	d[num]=time
	for nx in q[num]:
		if d[nx]==0:
			time+=1
			dfs(q,nx)
	time+=1
	f[num]=time
	
for i in range(n):
	if d[i]==0:#unvisit
		dfs(A,i)
		time+=1

for i in range(n):
	print(i+1,d[i],f[i])
