def nxt(u)
	u.each do |val|
		if $d[val] == nil
			return val
		end
	end
	return nil
end

def dfs(u)
	$cnt += 1
	$stk.push(u)
	$d[u] = $cnt
	while $stk != []
		u = nxt($l[$stk.last])
		if u != nil
			$stk.push(u)
			$cnt += 1
			$d[u] = $cnt
		else
			$cnt += 1
			$f[$stk.pop] = $cnt
		end
	end
end


n = gets.chomp.to_i
$l=[]
n.times do
	u, k, *v = gets.chomp.split(" ").map(&:to_i)
	$l[u] = v
end
$stk = []
$d = []
$f = []
$cnt=0

1.upto(n) do |i|
	if $d[i] == nil
		dfs(i)
	end
end

1.upto(n) do |i|
	print "#{i} #{$d[i]} #{$f[i]}\n"
end
