#include <iostream>
using namespace std;

const int MAX_N = 110;
int G[MAX_N][MAX_N];
int D[MAX_N], F[MAX_N], V[MAX_N];

void dfs(int u, int n, int& count) {
  int i;
  V[u] = 1;
  D[u] = ++count;
  for (i = 0; i < n; ++i) {
    if (G[u][i] && !V[i]) {
      dfs(i, n, count);
    }
  }
  F[u] = ++count;
}

int main() {
  int i, j, u, k, v, n, count;
  
  cin >> n;

  for (i = 0; i < n; ++i) {
    cin >> u >> k;
    for (j = 0; j < k; ++j) {
      cin >> v;
      G[u - 1][v - 1] = 1;
    }
  }

  count = 0;
  for (i = 0; i < n; ++i) {
    if (!V[i]) dfs(i,n,count);
  }

  for (i = 0; i < n; ++i) {
    cout << i + 1 << ' ' << D[i] << ' ' << F[i] << '\n';
  }

  return 0;
}
