# 目次
# 解答
#define INTMAX (1 << 21)
void dfs(vector<Int> vs[], Int n) {
Int t = 0;
bool visited[n];
Int ds[n];
Int fs[n];
loop(i,0,n) {
visited[i] = false;
ds[i] = fs[i] = 0;
}
stack<Int> S;
loop(i,0,n) {
if (visited[i]) continue;
S.push(i);
visited[i] = true;
ds[i] = ++t;
loop:
while (!S.empty()) {
Int i = S.top();
for (auto c: vs[i]) {
if (visited[c]) continue;
S.push(c);
visited[c] = true;
ds[c] = ++t;
goto loop;
}
S.pop();
fs[i] = ++t;
}
}
loop(i,0,n) cout << i+1 << " " << ds[i] << " " << fs[i] << endl;
}
int main(void){
Int n, x, cc, c;
cin >> n;
vector<Int> vs[n];
loop(i,0,n) {
cin >> x >> cc;
loop(j,0,cc) {
cin >> c;
vs[x-1].push_back(c-1);
}
}
dfs(vs, n);
}