#include<bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1000;
vector< vector<int> > G(N);
int d[N],f[N],visited[N];
int timer = 1;

void dfs(int s){
  d[s] = timer++;
  visited[s] = 1;
  for(int i = 0; i < G[s].size(); i++){
    int v = G[s][i];
    if(!visited[v]) dfs(v);
  }
  f[s] = timer++;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  for(int i = 0; i < n; i++){
    int u,k; cin >> u >> k;
    for(int j = 0; j < k; j++){
      int v; cin >> v;
      G[u].push_back(v);
    }
  }

  for(int i = 1; i <= n; i++){
    if(!visited[i]) dfs(i);
  }
  for(int i = 1; i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }

  return 0;
}

