N = int(input())
UKV = [list(map(int,input().split())) for _ in range(N)]

seen = [False]*N
first_time = [-1]*N
last_time = [-1]*N
time = 0
def dfs(G, v):
    global seen
    global first_time
    global last_time
    global time
    seen[v-1] = True
    time += 1
    first_time[v-1] = time
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)
    time += 1
    last_time[v-1] = time

G = {}
for ukv in UKV:
    G[ukv[0]] = sorted(ukv[2:])
for i in range(1,N+1):
    if seen[i-1]:
        continue
    dfs(G, i)

for i in range(1,N+1):
    print(i,first_time[i-1],last_time[i-1]) N = int(input()) N int(input()) int input() input list(map(int,input().split())) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split UKV = [list(map(int,input().split())) for _ in range(N)] UKV [list(map(int,input().split())) for _ in range(N)] seen = [False]*N seen [False]*N [False] False N first_time = [-1]*N first_time [-1]*N [-1] -1 N last_time = [-1]*N last_time [-1]*N [-1] -1 N time = 0 time 0 def dfs(G, v):
    global seen
    global first_time
    global last_time
    global time
    seen[v-1] = True
    time += 1
    first_time[v-1] = time
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)
    time += 1
    last_time[v-1] = time dfs global seen global first_time global last_time global time seen[v-1] = True seen[v-1] seen v-1 v 1 True time += 1 time 1 first_time[v-1] = time first_time[v-1] first_time v-1 v 1 time for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)
     next_v G[v] G v if seen[next_v-1]:
            continue
         seen[next_v-1] seen next_v-1 next_v 1 continue dfs(G, next_v) dfs G next_v time += 1 time 1 last_time[v-1] = time last_time[v-1] last_time v-1 v 1 time G G v v G = {} G {} for ukv in UKV:
    G[ukv[0]] = sorted(ukv[2:]) ukv UKV G[ukv[0]] = sorted(ukv[2:]) G[ukv[0]] G ukv[0] ukv 0 sorted(ukv[2:]) sorted ukv[2:] ukv 2: 2 for i in range(1,N+1):
    if seen[i-1]:
        continue
    dfs(G, i) i range(1,N+1) range 1 N+1 N 1 if seen[i-1]:
        continue
     seen[i-1] seen i-1 i 1 continue dfs(G, i) dfs G i for i in range(1,N+1):
    print(i,first_time[i-1],last_time[i-1]) i range(1,N+1) range 1 N+1 N 1 print(i,first_time[i-1],last_time[i-1]) print i first_time[i-1] first_time i-1 i 1 last_time[i-1] last_time i-1 i 1 UKV = [list(map(int,input().split())) for _ in range(N)] [list(map(int,input().split())) for _ in range(N)] UKV last_time = [-1]*N [-1]*N last_time time = 0 0 time def dfs(G, v):
    global seen
    global first_time
    global last_time
    global time
    seen[v-1] = True
    time += 1
    first_time[v-1] = time
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)
    time += 1
    last_time[v-1] = time def dfs(G, v):
    global seen
    global first_time
    global last_time
    global time
    seen[v-1] = True
    time += 1
    first_time[v-1] = time
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)
    time += 1
    last_time[v-1] = time dfs seen = [False]*N [False]*N seen first_time = [-1]*N [-1]*N first_time N = int(input()) int(input()) N G = {} {} G
N = int(input())
UKV = [list(map(int,input().split())) for _ in range(N)]

seen = [False]*N
first_time = [-1]*N
last_time = [-1]*N
time = 0
def dfs(G, v):
    global seen
    global first_time
    global last_time
    global time
    seen[v-1] = True
    time += 1
    first_time[v-1] = time
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)
    time += 1
    last_time[v-1] = time

G = {}
for ukv in UKV:
    G[ukv[0]] = sorted(ukv[2:])
for i in range(1,N+1):
    if seen[i-1]:
        continue
    dfs(G, i)

for i in range(1,N+1):
    print(i,first_time[i-1],last_time[i-1])
