# initialize
@list = []
@d = []
@f = []
@time = 0

# depth first search
def d_search(i)
  @time += 1
  @d[i] = @time


  @list[i].sort.each do |j|
    d_search(j-1) unless @d[j-1]
  end

  @time += 1
  @f[i] = @time
end

# main
n = gets.to_i
n.times do
  u, k, *v = gets.split.map {|i| i.to_i}
  @list[u-1] = v
end

d_search(0)

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