#include <iostream>
using namespace std;

int adja[101][101];
int stamp1[101], stamp2[101];
int n, cur = 1;

void dfs(int u) {
    stamp1[u] = cur++;
    for (int i = 1; i <= n; ++i) {
        if (adja[u][i] && stamp1[i] == 0)
            dfs(i);
    }
    stamp2[u] = cur++;
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            adja[u][v] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (stamp1[i] == 0)
            dfs(i);
        cout << i << " " << stamp1[i] << " " << stamp2[i] << endl;
    }

    return 0;
}

