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 << []
$d = Array.new(n+1,0)
$f = Array.new(n+1,0)
n.times do
  l = gets.split.map(&:to_i)
  $adj << l[2..-1]
end
(1..n).each do |i|
  $visited = Array.new(n+1)
  $visited[0] = true
  $cnt = 1
  dfs(i)
  if $visited.all?{|v| v}
    (1..n).each do |i|
      print i, " ", $d[i], " ", $f[i]
      puts
    end
    break
  end
end