def dfs(src)
  D[src] = $time
  $time += 1
  (0..N - 1).each do |dst|
    if D[dst] == nil && G[src][dst] == 1
      # Back[dst] = src
      dfs(dst)
    end
  end
  F[src] = $time
  $time += 1
  # p D
  # p F
  # p $time
  # dfs(Back[src]) if Back[src]
end

N = gets.to_i
G = (1..N).map{ Array.new(N, 0) }
N.times do
  u, k, *v = gets.split(' ').map(&:to_i)
  v.each do |vi|
    G[u - 1][vi - 1] = 1
  end
end

D = Array.new(N) #??????????¨????????????????
F = Array.new(N) #?????£???????????????
# Back = Array.new(N) #??????n????????¨?????????????????\??????

$time = 1

(0..N-1).each do |id|
  dfs(id) unless D[id]
end

(0..N-1).each do |id|
  puts "#{id + 1} #{D[id]} #{F[id]}"
end