#!/usr/bin/python3

def find(A, id, V, time):
    i = id - 1
    A[i][0] = True
    A[i][1] = time
    time += 1
    for v in V[i]:
        if A[v - 1][0] == False:
            time = find(A, v, V, time)
    A[i][2] = time
    time += 1
    return time

n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:])

time = 1
for u in U:
    if A[u - 1][0] == False:
        time = find(A, u, V, time)

for u in U:
    l = [u]
    l.extend(A[u - 1][1:])
    print(' '.join(map(str, l))) def find(A, id, V, time):
    i = id - 1
    A[i][0] = True
    A[i][1] = time
    time += 1
    for v in V[i]:
        if A[v - 1][0] == False:
            time = find(A, v, V, time)
    A[i][2] = time
    time += 1
    return time find i = id - 1 i id - 1 id 1 A[i][0] = True A[i][0] [i] A i 0 True A[i][1] = time A[i][1] [i] A i 1 time time += 1 time 1 for v in V[i]:
        if A[v - 1][0] == False:
            time = find(A, v, V, time)
     v V[i] V i if A[v - 1][0] == False:
            time = find(A, v, V, time)
     A[v - 1][0] == False A[v - 1][0] [v - 1] A v - 1 v 1 0 False time = find(A, v, V, time) time find(A, v, V, time) find A v V time A[i][2] = time A[i][2] [i] A i 2 time time += 1 time 1 return time time A A id id V V time time n = int(input()) n int(input()) int input() input [False, 0, 0] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [False, 0, 0] False 0 0 A = [[False, 0, 0] for i in range(n)] A [[False, 0, 0] for i in range(n)] U = [] U [] V = [] V [] for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:]) i range(n) range n l = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split U.append(l[0]) U.append U append l[0] l 0 V.append(l[2:]) V.append V append l[2:] l 2: 2 time = 1 time 1 for u in U:
    if A[u - 1][0] == False:
        time = find(A, u, V, time) u U if A[u - 1][0] == False:
        time = find(A, u, V, time) A[u - 1][0] == False A[u - 1][0] [u - 1] A u - 1 u 1 0 False time = find(A, u, V, time) time find(A, u, V, time) find A u V time for u in U:
    l = [u]
    l.extend(A[u - 1][1:])
    print(' '.join(map(str, l))) u U l = [u] l [u] u l.extend(A[u - 1][1:]) l.extend l extend A[u - 1][1:] [u - 1] A u - 1 u 1 1: 1 print(' '.join(map(str, l))) print ' '.join(map(str, l)) ' '.join ' ' join map(str, l) map str l U = [] [] U l = list(map(int, input().split())) list(map(int, input().split())) l n = int(input()) int(input()) n def find(A, id, V, time):
    i = id - 1
    A[i][0] = True
    A[i][1] = time
    time += 1
    for v in V[i]:
        if A[v - 1][0] == False:
            time = find(A, v, V, time)
    A[i][2] = time
    time += 1
    return time def find(A, id, V, time):
    i = id - 1
    A[i][0] = True
    A[i][1] = time
    time += 1
    for v in V[i]:
        if A[v - 1][0] == False:
            time = find(A, v, V, time)
    A[i][2] = time
    time += 1
    return time find time = find(A, u, V, time) find(A, u, V, time) time l = [u] [u] l A = [[False, 0, 0] for i in range(n)] [[False, 0, 0] for i in range(n)] A time = 1 1 time V = [] [] V
#!/usr/bin/python3

def find(A, id, V, time):
    i = id - 1
    A[i][0] = True
    A[i][1] = time
    time += 1
    for v in V[i]:
        if A[v - 1][0] == False:
            time = find(A, v, V, time)
    A[i][2] = time
    time += 1
    return time

n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:])

time = 1
for u in U:
    if A[u - 1][0] == False:
        time = find(A, u, V, time)

for u in U:
    l = [u]
    l.extend(A[u - 1][1:])
    print(' '.join(map(str, l)))