#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

cnt = 1
def solve():
    global cnt
    def dfs(x):
        global cnt
        f[x] = cnt
        for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
        f[x] = cnt
        cnt += 1

    n = I()
    v = []
    for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
    d = [0]*n
    f = [0]*n
    for i in range(n):
        if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])
    return

#Solve
if __name__ == "__main__":
    solve()
 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations import sys sys import math math import bisect bisect int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def I(): return int(sys.stdin.readline()) I list(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() list(x) list x def LS():return [list(x) for x in sys.stdin.readline().split()] LS def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res S res = list(sys.stdin.readline()) res list(sys.stdin.readline()) list sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline if res[-1] == "\n":
        return res[:-1]
     res[-1] == "\n" res[-1] res -1 "\n" return res[:-1] res[:-1] res :-1 -1 return res res def IR(n):
    return [I() for i in range(n)] IR I() for i in range(n) for i in range(n) i range(n) range n for i in range(n) I() I return [I() for i in range(n)] [I() for i in range(n)] n n def LIR(n):
    return [LI() for i in range(n)] LIR LI() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LI() LI return [LI() for i in range(n)] [LI() for i in range(n)] n n def SR(n):
    return [S() for i in range(n)] SR S() for i in range(n) for i in range(n) i range(n) range n for i in range(n) S() S return [S() for i in range(n)] [S() for i in range(n)] n n def LSR(n):
    return [LS() for i in range(n)] LSR LS() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LS() LS return [LS() for i in range(n)] [LS() for i in range(n)] n n sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 1000000007 mod 1000000007 cnt = 1 cnt 1 def solve():
    global cnt
    def dfs(x):
        global cnt
        f[x] = cnt
        for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
        f[x] = cnt
        cnt += 1

    n = I()
    v = []
    for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
    d = [0]*n
    f = [0]*n
    for i in range(n):
        if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])
    return

#Solve solve global cnt def dfs(x):
        global cnt
        f[x] = cnt
        for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
        f[x] = cnt
        cnt += 1

     dfs global cnt f[x] = cnt f[x] f x cnt for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
         y v[x] v x if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
         not d[y] d[y] d y d[y] = cnt d[y] d y cnt cnt += 1 cnt 1 dfs(y) dfs y f[x] = cnt f[x] f x cnt cnt += 1 cnt 1 x x n = I() n I() I v = [] v [] for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
     i range(n) range n e = LI() e LI() LI u = e[2:] u e[2:] e 2: 2 for i in range(len(u)):
            u[i] -= 1
         i range(len(u)) range len(u) len u u[i] -= 1 u[i] u i 1 v.append(u) v.append v append u d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n for i in range(n):
        if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
     i range(n) range n if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
     not d[i] d[i] d i d[i] = cnt d[i] d i cnt cnt += 1 cnt 1 dfs(i) dfs i for i in range(n):
        print(i+1,d[i],f[i])
     i range(n) range n print(i+1,d[i],f[i]) print i+1 i 1 d[i] d i f[i] f i return if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res S def LSR(n):
    return [LS() for i in range(n)] def LSR(n):
    return [LS() for i in range(n)] LSR def IR(n):
    return [I() for i in range(n)] def IR(n):
    return [I() for i in range(n)] IR def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def LS():return [list(x) for x in sys.stdin.readline().split()] def LS():return [list(x) for x in sys.stdin.readline().split()] LS cnt = 1 1 cnt def solve():
    global cnt
    def dfs(x):
        global cnt
        f[x] = cnt
        for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
        f[x] = cnt
        cnt += 1

    n = I()
    v = []
    for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
    d = [0]*n
    f = [0]*n
    for i in range(n):
        if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])
    return

#Solve def solve():
    global cnt
    def dfs(x):
        global cnt
        f[x] = cnt
        for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
        f[x] = cnt
        cnt += 1

    n = I()
    v = []
    for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
    d = [0]*n
    f = [0]*n
    for i in range(n):
        if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])
    return

#Solve solve def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def LIR(n):
    return [LI() for i in range(n)] def LIR(n):
    return [LI() for i in range(n)] LIR def SR(n):
    return [S() for i in range(n)] def SR(n):
    return [S() for i in range(n)] SR mod = 1000000007 1000000007 mod
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

cnt = 1
def solve():
    global cnt
    def dfs(x):
        global cnt
        f[x] = cnt
        for y in v[x]:
            if not d[y]:
                d[y] = cnt
                cnt += 1
                dfs(y)
        f[x] = cnt
        cnt += 1

    n = I()
    v = []
    for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
    d = [0]*n
    f = [0]*n
    for i in range(n):
        if not d[i]:
            d[i] = cnt
            cnt += 1
            dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])
    return

#Solve
if __name__ == "__main__":
    solve()

