import sys
input = sys.stdin.readline

from collections import deque

S = deque([])

def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        M[i][A[k]-1] = 1


def dfs(u):
    global t
    t = t + 1
    S.append(u)
    c[u] = 1
    d[u] = t

    for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
    c[u] = 2
    t += 1
    f[u] = t


n = int(input())
#color
c = [0] * n
d = [0] * n
f = [0] * n

M = [[0] * n for _ in range(n)]
t = 0

for i in range(n):
    A = list(map(int, input().split()))
    getNeighbor(A,i)

for num in range(n):
    if d[num] == 0:
        dfs(num)

for i in range(n):
    print(str(i+1), str(d[i]), str(f[i]))







 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import deque S = deque([]) S deque([]) deque [] def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        M[i][A[k]-1] = 1 getNeighbor a = len(A) a len(A) len A for k in range(2, a):
        M[i][A[k]-1] = 1 k range(2, a) range 2 a M[i][A[k]-1] = 1 M[i][A[k]-1] [i] M i A[k]-1 A[k] A k 1 1 A A i i def dfs(u):
    global t
    t = t + 1
    S.append(u)
    c[u] = 1
    d[u] = t

    for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
    c[u] = 2
    t += 1
    f[u] = t dfs global t t = t + 1 t t + 1 t 1 S.append(u) S.append S append u c[u] = 1 c[u] c u 1 d[u] = t d[u] d u t for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
     v range(n) range n if M[u][v] and c[v] == 0:
            dfs(v)
     M[u][v] and c[v] == 0 M[u][v] [u] M u v c[v] == 0 c[v] c v 0 dfs(v) dfs v c[u] = 2 c[u] c u 2 t += 1 t 1 f[u] = t f[u] f u t u u n = int(input()) n int(input()) int input() input c = [0] * n c [0] * n [0] 0 n d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n [0] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0] * n [0] 0 n M = [[0] * n for _ in range(n)] M [[0] * n for _ in range(n)] t = 0 t 0 for i in range(n):
    A = list(map(int, input().split()))
    getNeighbor(A,i) i range(n) range n A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split getNeighbor(A,i) getNeighbor A i for num in range(n):
    if d[num] == 0:
        dfs(num) num range(n) range n if d[num] == 0:
        dfs(num) d[num] == 0 d[num] d num 0 dfs(num) dfs num for i in range(n):
    print(str(i+1), str(d[i]), str(f[i])) i range(n) range n print(str(i+1), str(d[i]), str(f[i])) print str(i+1) str i+1 i 1 str(d[i]) str d[i] d i str(f[i]) str f[i] f i t = 0 0 t n = int(input()) int(input()) n input = sys.stdin.readline sys.stdin.readline input def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        M[i][A[k]-1] = 1 def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        M[i][A[k]-1] = 1 getNeighbor S = deque([]) deque([]) S A = list(map(int, input().split())) list(map(int, input().split())) A c = [0] * n [0] * n c f = [0] * n [0] * n f def dfs(u):
    global t
    t = t + 1
    S.append(u)
    c[u] = 1
    d[u] = t

    for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
    c[u] = 2
    t += 1
    f[u] = t def dfs(u):
    global t
    t = t + 1
    S.append(u)
    c[u] = 1
    d[u] = t

    for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
    c[u] = 2
    t += 1
    f[u] = t dfs d = [0] * n [0] * n d M = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] M
import sys
input = sys.stdin.readline

from collections import deque

S = deque([])

def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        M[i][A[k]-1] = 1


def dfs(u):
    global t
    t = t + 1
    S.append(u)
    c[u] = 1
    d[u] = t

    for v in range(n):
        if M[u][v] and c[v] == 0:
            dfs(v)
    c[u] = 2
    t += 1
    f[u] = t


n = int(input())
#color
c = [0] * n
d = [0] * n
f = [0] * n

M = [[0] * n for _ in range(n)]
t = 0

for i in range(n):
    A = list(map(int, input().split()))
    getNeighbor(A,i)

for num in range(n):
    if d[num] == 0:
        dfs(num)

for i in range(n):
    print(str(i+1), str(d[i]), str(f[i]))








