WHITE = 0
GRAY = 1
BLACK = 2



$d = []
$f = []



def dfs_visit(u)
	$color[u] = GRAY
	$tt += 1
	$d[u] = $tt

	$n.times do |v|
		next if $m[u][v] == 0
		dfs_visit(v) if $color[v] == WHITE
	end

	$color[u] = BLACK
	$tt += 1
	$f[u] = $tt
end



def dfs()
	$color = Array.new($n, WHITE)
	$tt = 0
	
	$n.times do |u|
		dfs_visit(u) if $color[u] == WHITE
	end

	$n.times do |u|
		printf("%d %d %d\n", u + 1, $d[u], $f[u])	
	end
end



$n = gets.to_i
$m = Array.new($n){ Array.new($n, 0) }

$n.times do
	line = gets.split.map &:to_i
	u, k = line.shift, line.shift
	u -= 1
	k.times do
		v = line.shift
		v -= 1
		$m[u][v] = 1
	end
end

dfs()