#if 0

#endif

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

vector<int> E[110];
int N;
int D[110], F[110];

int tim = 0;
void dfs(int cur) {
  tim += 1;
  D[cur] = tim;
  for (auto it = E[cur].begin(); it != E[cur].end(); ++it) {
    if (D[*it] == 0) {
      dfs(*it);
    }
  }
  tim += 1;
  F[cur] = tim;
}

int main() {
  cin >> N;
  int c, k;
  for (int i = 1; i <= N; i++) {
    cin >> c >> k;
    int t;
    for (int j = 0; j < k; j++) {
      cin >> t; E[i].push_back(t);
    }
  }
  for (int i = 1; i <= N; i++) {
    D[i] = 0; F[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    if (D[i] == 0)
      dfs(i);
  }
  for (int i = 1; i <= N; i++)
    cout << i << ' ' << D[i] << ' ' << F[i] << endl;
}

