count = 0


def solve(i, a, ans):
    global count
    if ans[i][0] == 0:
        count += 1
        ans[i][0] = count

    for x in range(a[i][1]):
        if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

    if ans[i][1] == 0:
        count += 1
        ans[i][1] = count


N = int(input())
a = []
for _ in range(N):
    a.append([int(x) for x in input().split()])

ans = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    if ans[i][0] == 0:
        solve(i, a, ans)

for i, x in enumerate(ans):
    print(i + 1, *x)



 count = 0 count 0 def solve(i, a, ans):
    global count
    if ans[i][0] == 0:
        count += 1
        ans[i][0] = count

    for x in range(a[i][1]):
        if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

    if ans[i][1] == 0:
        count += 1
        ans[i][1] = count solve global count if ans[i][0] == 0:
        count += 1
        ans[i][0] = count

     ans[i][0] == 0 ans[i][0] [i] ans i 0 0 count += 1 count 1 ans[i][0] = count ans[i][0] [i] ans i 0 count for x in range(a[i][1]):
        if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

     x range(a[i][1]) range a[i][1] [i] a i 1 if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

     ans[a[i][2 + x] - 1][0] == 0 ans[a[i][2 + x] - 1][0] [a[i][2 + x] - 1] ans a[i][2 + x] - 1 a[i][2 + x] [i] a i 2 + x 2 x 1 0 0 solve(a[i][2 + x] - 1, a, ans) solve a[i][2 + x] - 1 a[i][2 + x] [i] a i 2 + x 2 x 1 a ans if ans[i][1] == 0:
        count += 1
        ans[i][1] = count ans[i][1] == 0 ans[i][1] [i] ans i 1 0 count += 1 count 1 ans[i][1] = count ans[i][1] [i] ans i 1 count i i a a ans ans N = int(input()) N int(input()) int input() input a = [] a [] for _ in range(N):
    a.append([int(x) for x in input().split()]) _ range(N) range N int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x a.append([int(x) for x in input().split()]) a.append a append [int(x) for x in input().split()] [0 for i in range(2)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(2)] ans = [[0 for i in range(2)] for j in range(N)] ans [[0 for i in range(2)] for j in range(N)] for i in range(N):
    if ans[i][0] == 0:
        solve(i, a, ans) i range(N) range N if ans[i][0] == 0:
        solve(i, a, ans) ans[i][0] == 0 ans[i][0] [i] ans i 0 0 solve(i, a, ans) solve i a ans for i, x in enumerate(ans):
    print(i + 1, *x) i x enumerate(ans) enumerate ans print(i + 1, *x) print i + 1 i 1 *x x def solve(i, a, ans):
    global count
    if ans[i][0] == 0:
        count += 1
        ans[i][0] = count

    for x in range(a[i][1]):
        if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

    if ans[i][1] == 0:
        count += 1
        ans[i][1] = count def solve(i, a, ans):
    global count
    if ans[i][0] == 0:
        count += 1
        ans[i][0] = count

    for x in range(a[i][1]):
        if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

    if ans[i][1] == 0:
        count += 1
        ans[i][1] = count solve count = 0 0 count a = [] [] a ans = [[0 for i in range(2)] for j in range(N)] [[0 for i in range(2)] for j in range(N)] ans N = int(input()) int(input()) N
count = 0


def solve(i, a, ans):
    global count
    if ans[i][0] == 0:
        count += 1
        ans[i][0] = count

    for x in range(a[i][1]):
        if ans[a[i][2 + x] - 1][0] == 0:
            solve(a[i][2 + x] - 1, a, ans)

    if ans[i][1] == 0:
        count += 1
        ans[i][1] = count


N = int(input())
a = []
for _ in range(N):
    a.append([int(x) for x in input().split()])

ans = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    if ans[i][0] == 0:
        solve(i, a, ans)

for i, x in enumerate(ans):
    print(i + 1, *x)




