from typing import List

def DFS(G: List[int]):
	global time
	time = 0
	n = len(G)
	for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u)

def DFS_Visit(u: int):
	global time
	color[u] = "GRAY"
	time += 1
	d[u] = time
	for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	color[u] = "BLACK"
	time += 1
	f[u] = time


if __name__ == "__main__":
	n = int(input())
	G = []
	color = ["WHITE" for _ in range(n)]
	pi = [None for _ in range(n)]
	d = [0 for _ in range(n)]
	f = [0 for _ in range(n)]

	for _ in range(n):
		command = list(map(int, input().split()))
		G.append([x - 1 for x in command[2:]])
	DFS(G)
	for i in range(n):
		print(f"{i + 1} {d[i]} {f[i]}") from typing import List def DFS(G: List[int]):
	global time
	time = 0
	n = len(G)
	for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u) DFS global time time = 0 time 0 n = len(G) n len(G) len G for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u) u range(n) range n if color[u] == "WHITE":
			DFS_Visit(u) color[u] == "WHITE" color[u] color u "WHITE" DFS_Visit(u) DFS_Visit u G: List[int] G def DFS_Visit(u: int):
	global time
	color[u] = "GRAY"
	time += 1
	d[u] = time
	for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	color[u] = "BLACK"
	time += 1
	f[u] = time DFS_Visit global time color[u] = "GRAY" color[u] color u "GRAY" time += 1 time 1 d[u] = time d[u] d u time for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	 v G[u] G u if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	 color[v] == "WHITE" color[v] color v "WHITE" pi[v] = u pi[v] pi v u DFS_Visit(v) DFS_Visit v color[u] = "BLACK" color[u] color u "BLACK" time += 1 time 1 f[u] = time f[u] f u time u: int u if __name__ == "__main__":
	n = int(input())
	G = []
	color = ["WHITE" for _ in range(n)]
	pi = [None for _ in range(n)]
	d = [0 for _ in range(n)]
	f = [0 for _ in range(n)]

	for _ in range(n):
		command = list(map(int, input().split()))
		G.append([x - 1 for x in command[2:]])
	DFS(G)
	for i in range(n):
		print(f"{i + 1} {d[i]} {f[i]}") __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input G = [] G [] "WHITE" for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) "WHITE" color = ["WHITE" for _ in range(n)] color ["WHITE" for _ in range(n)] None for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) None pi = [None for _ in range(n)] pi [None for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 d = [0 for _ in range(n)] d [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 f = [0 for _ in range(n)] f [0 for _ in range(n)] for _ in range(n):
		command = list(map(int, input().split()))
		G.append([x - 1 for x in command[2:]])
	 _ range(n) range n command = list(map(int, input().split())) command list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split x - 1 for x in command[2:] for x in command[2:] x command[2:] command 2: 2 for x in command[2:] x - 1 x 1 G.append([x - 1 for x in command[2:]]) G.append G append [x - 1 for x in command[2:]] DFS(G) DFS G for i in range(n):
		print(f"{i + 1} {d[i]} {f[i]}") i range(n) range n print(f"{i + 1} {d[i]} {f[i]}") print f"{i + 1} {d[i]} {f[i]}" pi = [None for _ in range(n)] [None for _ in range(n)] pi f = [0 for _ in range(n)] [0 for _ in range(n)] f def DFS(G: List[int]):
	global time
	time = 0
	n = len(G)
	for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u) def DFS(G: List[int]):
	global time
	time = 0
	n = len(G)
	for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u) DFS color = ["WHITE" for _ in range(n)] ["WHITE" for _ in range(n)] color d = [0 for _ in range(n)] [0 for _ in range(n)] d def DFS_Visit(u: int):
	global time
	color[u] = "GRAY"
	time += 1
	d[u] = time
	for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	color[u] = "BLACK"
	time += 1
	f[u] = time def DFS_Visit(u: int):
	global time
	color[u] = "GRAY"
	time += 1
	d[u] = time
	for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	color[u] = "BLACK"
	time += 1
	f[u] = time DFS_Visit n = int(input()) int(input()) n command = list(map(int, input().split())) list(map(int, input().split())) command G = [] [] G
from typing import List

def DFS(G: List[int]):
	global time
	time = 0
	n = len(G)
	for u in range(n):
		if color[u] == "WHITE":
			DFS_Visit(u)

def DFS_Visit(u: int):
	global time
	color[u] = "GRAY"
	time += 1
	d[u] = time
	for v in G[u]:
		if color[v] == "WHITE":
			pi[v] = u
			DFS_Visit(v)
	color[u] = "BLACK"
	time += 1
	f[u] = time


if __name__ == "__main__":
	n = int(input())
	G = []
	color = ["WHITE" for _ in range(n)]
	pi = [None for _ in range(n)]
	d = [0 for _ in range(n)]
	f = [0 for _ in range(n)]

	for _ in range(n):
		command = list(map(int, input().split()))
		G.append([x - 1 for x in command[2:]])
	DFS(G)
	for i in range(n):
		print(f"{i + 1} {d[i]} {f[i]}")
