def dfs(i, d, f, time, adj)
  time += 1
  d[i-1] = time
  
  adj[i-1].each do |j|
    time = dfs(j, d , f, time, adj) if d[j-1] == 0
  end
  
  time += 1
  f[i-1] = time
  return time
end

n = gets.to_i
adj = Array.new(n){ Array.new(3) }
n.times do
  u, k, *a = gets.split.map(&:to_i)
  adj[u-1] = a
end

d = Array.new(n, 0);
f = Array.new(n, 0);

time = 0
n.times do |i|
  time = dfs(i+1, d, f, time, adj) if d[i] == 0
end

(1..n).each do |i|
  puts "#{i} #{d[i-1]} #{f[i-1]}"
end