def dfs(i)
  $visited[i] = true
  $d[i] = $cnt
  $cnt += 1
  $adj[i].each do |v|
    unless $visited[v]
      dfs(v)
    end
  end
  $f[i] = $cnt
  $cnt += 1
end
n = gets.to_i
$adj = []
$adj << Array.new(n){ |i| i+1 }
$d = Array.new(n+1,0)
$f = Array.new(n+1,0)
n.times { $adj << gets.split.map(&:to_i)[2..-1] }

$visited = Array.new(n+1)
$cnt = 0
dfs(0)

(1..n).each do |i|
  print i, " ", $d[i], " ", $f[i]
  puts
end