# dfs.rb
#ALDS1_11_B

$n = STDIN.gets.split[0].to_i
$rinsetu = Array.new(101).map{Array.new(101,0)}
$d = Array.new(101,0)
$f = Array.new(101,0)

1.upto($n){|i|
  s = STDIN.gets.split
  u = s[0].to_i
  k = s[1].to_i
  0.upto(k-1){|j| 
    v = s[2+j].to_i
    $rinsetu[u][v] = 1
  }
}

def dfs(node,time)
    $d[node]=time
    1.upto($n) {|i|
      time = dfs(i,time+1) if node != i && $rinsetu[node][i]==1 && $d[i]==0
    }
    $f[node]=time+1
    time+1
end

dfs(1,1)

1.upto($n){|i|
  printf("%d %d %d\n",i,$d[i],$f[i])
}