n = gets.to_i
g = Array.new(n+1){ [] }

n.times do |i|
  u,k,*v = gets.split.map(&:to_i)
  g[u] += v if k > 0
end

d = Array.new(n+1, 0)
f = Array.new(n+1, 0)
t = 0

dfs = -> v do
  return if d[v] > 0
  t += 1; d[v] = t
  g[v].sort.each do |nv|
    dfs[nv]
  end
  t += 1; f[v] = t
end

1.upto(n) do |v|
  dfs[v]
end

1.upto(n) do |v|
  puts [v, d[v], f[v]].join(" ")
end

