n=int(input())
adj=[]
for i in range(n):
	a=list(map(int,input().split()))
	for j in range(2,len(a)):
		a[j]-=1
	adj.append(a[2:])
visit_time1=[0]*n
visit_time2=[0]*n
visited=[0]*n
def dfs(now):
	global time
	visit_time1[now]=time
	time+=1
	for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	visit_time2[now]=time
	time+=1
time=1
for i in range(n):
	if not visited[i]:
		visited[i]=True
		dfs(i)
for i in range(n):
	print(i+1,visit_time1[i],visit_time2[i]) n=int(input()) n int(input()) int input() input adj=[] adj [] for i in range(n):
	a=list(map(int,input().split()))
	for j in range(2,len(a)):
		a[j]-=1
	adj.append(a[2:]) 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(2,len(a)):
		a[j]-=1
	 j range(2,len(a)) range 2 len(a) len a a[j]-=1 a[j] a j 1 adj.append(a[2:]) adj.append adj append a[2:] a 2: 2 visit_time1=[0]*n visit_time1 [0]*n [0] 0 n visit_time2=[0]*n visit_time2 [0]*n [0] 0 n visited=[0]*n visited [0]*n [0] 0 n def dfs(now):
	global time
	visit_time1[now]=time
	time+=1
	for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	visit_time2[now]=time
	time+=1 dfs global time visit_time1[now]=time visit_time1[now] visit_time1 now time time+=1 time 1 for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	 next adj[now] adj now if not visited[next]:
			visited[next]=True
			dfs(next)
	 not visited[next] visited[next] visited next visited[next]=True visited[next] visited next True dfs(next) dfs next visit_time2[now]=time visit_time2[now] visit_time2 now time time+=1 time 1 now now time=1 time 1 for i in range(n):
	if not visited[i]:
		visited[i]=True
		dfs(i) i range(n) range n if not visited[i]:
		visited[i]=True
		dfs(i) not visited[i] visited[i] visited i visited[i]=True visited[i] visited i True dfs(i) dfs i for i in range(n):
	print(i+1,visit_time1[i],visit_time2[i]) i range(n) range n print(i+1,visit_time1[i],visit_time2[i]) print i+1 i 1 visit_time1[i] visit_time1 i visit_time2[i] visit_time2 i n=int(input()) int(input()) n visit_time1=[0]*n [0]*n visit_time1 a=list(map(int,input().split())) list(map(int,input().split())) a visited=[0]*n [0]*n visited adj=[] [] adj visit_time2=[0]*n [0]*n visit_time2 def dfs(now):
	global time
	visit_time1[now]=time
	time+=1
	for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	visit_time2[now]=time
	time+=1 def dfs(now):
	global time
	visit_time1[now]=time
	time+=1
	for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	visit_time2[now]=time
	time+=1 dfs time=1 1 time
n=int(input())
adj=[]
for i in range(n):
	a=list(map(int,input().split()))
	for j in range(2,len(a)):
		a[j]-=1
	adj.append(a[2:])
visit_time1=[0]*n
visit_time2=[0]*n
visited=[0]*n
def dfs(now):
	global time
	visit_time1[now]=time
	time+=1
	for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	visit_time2[now]=time
	time+=1
time=1
for i in range(n):
	if not visited[i]:
		visited[i]=True
		dfs(i)
for i in range(n):
	print(i+1,visit_time1[i],visit_time2[i])
