def dfs(G,n):

	global ptr
	
	#探索済
	seen[n] = True

	#行き
	F[n] = ptr
	ptr += 1

	for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	L[n] = ptr
	ptr += 1

if __name__ == '__main__':

	n = int(input())
	
	G = [[] for _ in range(n+1)] 
	F = [0 for _ in range(n+1)]
	L = [0 for _ in range(n+1)]

	#深さ優先探索
	#探索済配列
	seen = [False for _ in range(n+1)]

	for i in range(n):
		cmd = list(map(int,input().split()))
		m = cmd[1]
		if m != 0:
			for j in range(m):
				G[i+1].append(cmd[j+2])
	ptr = 1
	for i in range(1,n):
		if seen[i] == False :
			dfs(G,i)

	for i in range(1,n+1):
		print(i,F[i],L[i])

 def dfs(G,n):

	global ptr
	
	#探索済
	seen[n] = True

	#行き
	F[n] = ptr
	ptr += 1

	for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	L[n] = ptr
	ptr += 1 dfs global ptr seen[n] = True seen[n] seen n True F[n] = ptr F[n] F n ptr ptr += 1 ptr 1 for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	 i G[n] G n if seen[i] == True :
			continue
		 seen[i] == True seen[i] seen i True continue dfs(G,i) dfs G i L[n] = ptr L[n] L n ptr ptr += 1 ptr 1 G G n n if __name__ == '__main__':

	n = int(input())
	
	G = [[] for _ in range(n+1)] 
	F = [0 for _ in range(n+1)]
	L = [0 for _ in range(n+1)]

	#深さ優先探索
	#探索済配列
	seen = [False for _ in range(n+1)]

	for i in range(n):
		cmd = list(map(int,input().split()))
		m = cmd[1]
		if m != 0:
			for j in range(m):
				G[i+1].append(cmd[j+2])
	ptr = 1
	for i in range(1,n):
		if seen[i] == False :
			dfs(G,i)

	for i in range(1,n+1):
		print(i,F[i],L[i]) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] G = [[] for _ in range(n+1)] G [[] for _ in range(n+1)] 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 F = [0 for _ in range(n+1)] F [0 for _ in range(n+1)] 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 L = [0 for _ in range(n+1)] L [0 for _ in range(n+1)] False for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) False seen = [False for _ in range(n+1)] seen [False for _ in range(n+1)] for i in range(n):
		cmd = list(map(int,input().split()))
		m = cmd[1]
		if m != 0:
			for j in range(m):
				G[i+1].append(cmd[j+2])
	 i range(n) range n cmd = list(map(int,input().split())) cmd list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split m = cmd[1] m cmd[1] cmd 1 if m != 0:
			for j in range(m):
				G[i+1].append(cmd[j+2])
	 m != 0 m 0 for j in range(m):
				G[i+1].append(cmd[j+2])
	 j range(m) range m G[i+1].append(cmd[j+2]) [i+1].append [i+1] G i+1 i 1 append cmd[j+2] cmd j+2 j 2 ptr = 1 ptr 1 for i in range(1,n):
		if seen[i] == False :
			dfs(G,i)

	 i range(1,n) range 1 n if seen[i] == False :
			dfs(G,i)

	 seen[i] == False seen[i] seen i False dfs(G,i) dfs G i for i in range(1,n+1):
		print(i,F[i],L[i]) i range(1,n+1) range 1 n+1 n 1 print(i,F[i],L[i]) print i F[i] F i L[i] L i m = cmd[1] cmd[1] m cmd = list(map(int,input().split())) list(map(int,input().split())) cmd ptr = 1 1 ptr n = int(input()) int(input()) n seen = [False for _ in range(n+1)] [False for _ in range(n+1)] seen L = [0 for _ in range(n+1)] [0 for _ in range(n+1)] L F = [0 for _ in range(n+1)] [0 for _ in range(n+1)] F def dfs(G,n):

	global ptr
	
	#探索済
	seen[n] = True

	#行き
	F[n] = ptr
	ptr += 1

	for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	L[n] = ptr
	ptr += 1 def dfs(G,n):

	global ptr
	
	#探索済
	seen[n] = True

	#行き
	F[n] = ptr
	ptr += 1

	for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	L[n] = ptr
	ptr += 1 dfs G = [[] for _ in range(n+1)] [[] for _ in range(n+1)] G
def dfs(G,n):

	global ptr
	
	#探索済
	seen[n] = True

	#行き
	F[n] = ptr
	ptr += 1

	for i in G[n]:
		#次に行けるかを判定
		if seen[i] == True :
			continue
		dfs(G,i)

	#帰り
	L[n] = ptr
	ptr += 1

if __name__ == '__main__':

	n = int(input())
	
	G = [[] for _ in range(n+1)] 
	F = [0 for _ in range(n+1)]
	L = [0 for _ in range(n+1)]

	#深さ優先探索
	#探索済配列
	seen = [False for _ in range(n+1)]

	for i in range(n):
		cmd = list(map(int,input().split()))
		m = cmd[1]
		if m != 0:
			for j in range(m):
				G[i+1].append(cmd[j+2])
	ptr = 1
	for i in range(1,n):
		if seen[i] == False :
			dfs(G,i)

	for i in range(1,n+1):
		print(i,F[i],L[i])


