# encoding: utf-8

$start_time = [0] * 100
$end_time = [0] * 100
$step = 1
$map = []
$vis = [false] * 100
def build_map
  $n = gets.rstrip.to_i
  $map = []
  $n.times { $map << [0] * $n}
  (1..$n).each do |node|
    arr = gets.rstrip.split(/\s/).map(&:to_i)
    u, k = arr[0], arr[1]
    node = arr[2..-1]
    node.each { |v| $map[u - 1][v - 1] = 1}
  end
end

def dfs(x)
  $start_time[x] = $step
  $step += 1
  $vis[x] = true
  $map[x].each_with_index do |node, idx|
    if node == 1 and not $vis[idx]
      dfs(idx)
    end
  end
  $end_time[x] = $step
  $step += 1
end

def solve
  build_map
  dfs 0
end

solve

(0..($n - 1)).each do |idx|
  puts "#{idx + 1} #{$start_time[idx]} #{$end_time[idx]}"
end