import sys
sys.setrecursionlimit(2000000)

n = int(input())
m = [list(map(int, input().split()))[2:] for _ in range(n)]

def dfs(x, time):
    first[x] = time
    time += 1
    for v in m[x]:
        if first[v-1] == 0:
            time = dfs(v-1, time)
    finish[x] = time
    time += 1
    return time

first = [0] * n
finish = [0] * n

time = 1
for i in range(n):
    if first[i] == 0:
        time = dfs(i, time)

for i, xy in enumerate(zip(first, finish)):
    print(i+1, *xy) import sys sys sys.setrecursionlimit(2000000) sys.setrecursionlimit sys setrecursionlimit 2000000 n = int(input()) n int(input()) int input() input list(map(int, input().split()))[2:] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int, input().split()))[2:] (map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 2: 2 m = [list(map(int, input().split()))[2:] for _ in range(n)] m [list(map(int, input().split()))[2:] for _ in range(n)] def dfs(x, time):
    first[x] = time
    time += 1
    for v in m[x]:
        if first[v-1] == 0:
            time = dfs(v-1, time)
    finish[x] = time
    time += 1
    return time dfs first[x] = time first[x] first x time time += 1 time 1 for v in m[x]:
        if first[v-1] == 0:
            time = dfs(v-1, time)
     v m[x] m x if first[v-1] == 0:
            time = dfs(v-1, time)
     first[v-1] == 0 first[v-1] first v-1 v 1 0 time = dfs(v-1, time) time dfs(v-1, time) dfs v-1 v 1 time finish[x] = time finish[x] finish x time time += 1 time 1 return time time x x time time first = [0] * n first [0] * n [0] 0 n finish = [0] * n finish [0] * n [0] 0 n time = 1 time 1 for i in range(n):
    if first[i] == 0:
        time = dfs(i, time) i range(n) range n if first[i] == 0:
        time = dfs(i, time) first[i] == 0 first[i] first i 0 time = dfs(i, time) time dfs(i, time) dfs i time for i, xy in enumerate(zip(first, finish)):
    print(i+1, *xy) i xy enumerate(zip(first, finish)) enumerate zip(first, finish) zip first finish print(i+1, *xy) print i+1 i 1 *xy xy m = [list(map(int, input().split()))[2:] for _ in range(n)] [list(map(int, input().split()))[2:] for _ in range(n)] m n = int(input()) int(input()) n first = [0] * n [0] * n first time = dfs(i, time) dfs(i, time) time time = 1 1 time def dfs(x, time):
    first[x] = time
    time += 1
    for v in m[x]:
        if first[v-1] == 0:
            time = dfs(v-1, time)
    finish[x] = time
    time += 1
    return time def dfs(x, time):
    first[x] = time
    time += 1
    for v in m[x]:
        if first[v-1] == 0:
            time = dfs(v-1, time)
    finish[x] = time
    time += 1
    return time dfs finish = [0] * n [0] * n finish
import sys
sys.setrecursionlimit(2000000)

n = int(input())
m = [list(map(int, input().split()))[2:] for _ in range(n)]

def dfs(x, time):
    first[x] = time
    time += 1
    for v in m[x]:
        if first[v-1] == 0:
            time = dfs(v-1, time)
    finish[x] = time
    time += 1
    return time

first = [0] * n
finish = [0] * n

time = 1
for i in range(n):
    if first[i] == 0:
        time = dfs(i, time)

for i, xy in enumerate(zip(first, finish)):
    print(i+1, *xy)
