using System.Collections;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Numerics;


class Program
{

    static void Main()
    {
        #region 入力
        int N = ReadInt;
        int[][] G = new int[N][];
        HashSet<int> yet = new HashSet<int>();
        for (int i = 0; i < N; i++) {
            G[i] = ReadInts;
            yet.Add(i);
        }
        #endregion

        int[][] ans = new int[N][];

        while (yet.Count > 0)
        {
            time++;
            DFS(yet.ElementAt(0), time, G, ans,yet);
        }
        foreach (var item in ans)
        {
            WriteLine(string.Join(" ",item));
        }
        ReadLine();
    }

    static int time = 0;
    static void DFS(int current,int foundTime,int[][] nodes,int[][] ans,HashSet<int> yet)
    {
        ans[current] = new int[3];
        ans[current][0] = current + 1;
        ans[current][1] = foundTime;
        yet.Remove(current);
        for (int i = 2; i < nodes[current].Length; i++)
        {
            if (ans[nodes[current][i] - 1] == null)
            {
                time++;
                DFS(nodes[current][i] - 1, time, nodes, ans,yet);
            }
        }
        time++;
        ans[current][2] = time;
    }

    static Vector2Int BinarySearch(IEnumerable<int> numbers, Func<int, bool> judge)
    {
        int max = numbers.Count();
        int min = -1;
        int mid = (min + max) / 2;

        while (max - min > 1)
        {
            if (judge(numbers.ElementAt(mid)))
            {
                min = mid;
                mid = (mid + max) / 2;
            }
            else
            {
                max = mid;
                mid = (mid + min) / 2;
            }
        }

        if (max == numbers.Count()) return new Vector2Int(mid, mid + 1);
        else if (min == -1) return new Vector2Int(-1, 0);
        else
        {
            return judge(numbers.ElementAt(mid)) != judge(numbers.ElementAt(mid + 1)) ? new Vector2Int(mid, mid + 1)
            : new Vector2Int(mid - 1, mid);
        }
    }


    struct Vector2Int
    {
        public Vector2Int(int x, int y)
        {
            X = x;
            Y = y;
        }
        public int X;
        public int Y;
        public double Magnitude => Math.Sqrt(X * X + Y * Y);

        public static Vector2Int zero => new Vector2Int(0, 0);
        public static Vector2Int u => new Vector2Int(0, 1);
        public static Vector2Int r => new Vector2Int(1, 0);
        public static Vector2Int d => new Vector2Int(0, -1);
        public static Vector2Int l => new Vector2Int(-1, 0);
        public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l };

        public static Vector2Int operator +(Vector2Int a, Vector2Int b)
        {
            return new Vector2Int(a.X + b.X, a.Y + b.Y);
        }
        public static Vector2Int operator -(Vector2Int a, Vector2Int b)
        {
            return new Vector2Int(a.X - b.X, a.Y - b.Y);
        }
        public static bool operator ==(Vector2Int a, Vector2Int b)
        {
            return a.X == b.X && a.Y == b.Y;
        }
        public static bool operator !=(Vector2Int a, Vector2Int b)
        {
            return a.X != b.X || a.Y != b.Y;
        }
        public static Vector2Int operator *(Vector2Int v, int n)
        {
            return new Vector2Int(v.X * n, v.Y * n);
        }
        public static Vector2Int operator *(int n, Vector2Int v)
        {
            return new Vector2Int(v.X * n, v.Y * n);
        }
    }
    struct Vector3Int
    {
        public Vector3Int(int x, int y, int z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        public int X;
        public int Y;
        public int Z;

        public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z);

        public static Vector3Int zero => new Vector3Int(0, 0, 0);
        public static Vector3Int u => new Vector3Int(0, 1, 0);
        public static Vector3Int r => new Vector3Int(1, 0, 0);
        public static Vector3Int d => new Vector3Int(0, -1, 0);
        public static Vector3Int l => new Vector3Int(-1, 0, 0);

        public static Vector3Int operator +(Vector3Int a, Vector3Int b)
        {
            return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
        }
        public static Vector3Int operator -(Vector3Int a, Vector3Int b)
        {
            return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
        }
        public static bool operator ==(Vector3Int a, Vector3Int b)
        {
            return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
        }
        public static bool operator !=(Vector3Int a, Vector3Int b)
        {
            return a.X != b.X || a.Y != b.Y || a.Z != b.Z;
        }
        public static Vector3Int operator *(Vector3Int v, int n)
        {
            return new Vector3Int(v.X * n, v.Y * n, v.Z * n);
        }
        public static Vector3Int operator *(int n, Vector3Int v)
        {
            return new Vector3Int(v.X * n, v.Y * n, v.Z * n);
        }
    }

    #region Reader
    static Vector2Int ReVec2Int { get {
            string[] s = Console.ReadLine().Split(' ');
            return new Vector2Int(int.Parse(s[0]), int.Parse(s[1]));
        } }
    static Vector2Int[] ReadVec2Ints(int n)
    {
        List<Vector2Int> list = new List<Vector2Int>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Vector2Int(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static HashSet<Vector2Int> ReadVec2IntHash(int n)
    {
        HashSet<Vector2Int> hash = new HashSet<Vector2Int>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            hash.Add(new Vector2Int(ab[0], ab[1]));
        }
        return hash;
    }
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static long[,] ReLongMatrix(int r, int c)
    {
        var mat = new long[r, c];
        for (int i = 0; i < r; ++i)
        {
            var x = ReadLongs;
            for (int j = 0; j < c; ++j)
            {
                mat[i, j] = x[j];
            }
        }
        return mat;
    }
    static Tuple<string, string>[] ReTupleStr(int n)
    {
        List<Tuple<string, string>> list = new List<Tuple<string, string>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadStrs;
            list.Add(new Tuple<string, string>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<long, long>[] ReTupleLong(int n)
    {
        List<Tuple<long, long>> list = new List<Tuple<long, long>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadLongs;
            list.Add(new Tuple<long, long>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<int, int>[] ReadTupleInt(int n)
    {
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Tuple<int, int>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<double, double>[] ReTupleDouble(int n)
    {
        List<Tuple<double, double>> list = new List<Tuple<double, double>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadLongs;
            list.Add(new Tuple<double, double>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M)
    {
        Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
        for (int i = 0; i <= N; ++i)
        {
            dict.Add(i, new HashSet<int>());
        }
        for (int i = 0; i < M; ++i)
        {
            var ab = ReadInts;
            dict[ab[0]].Add(ab[1]);
            dict[ab[1]].Add(ab[0]);
        }
        return dict;
    }
    #endregion
}


Measured memory_bytes: 18748