#include <bits/stdc++.h>

using namespace std;

const int N = 105;

int n, k, u, v, clok;
int d[N], f[N], mark[N];
vector<int> a[N];

void DFS(int p)
{
  mark[p] = 1;
  d[p] = clok;
  clok++;
  for(int i = 0; i < a[p].size(); i++)
    if(!mark[a[p][i]]){
      DFS(a[p][i]);
    }
  f[p] = clok;
  clok++;
}

int main()
{
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> u >> k;
    for(int j = 1; j <= k; j++) {
      cin >> v;
      a[u].push_back(v);
    }
    sort(a[u].begin(), a[u].end());
  }
  clok = 1;
  for(int i = 1; i <= n; i++)
    if(!mark[i]) DFS(i);
  for(int i = 1; i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

