import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)]
D = [-1]*N
D2 = [-1]*N
def dfs(cur, now):
    if D[cur] != -1: return now
    now += 1
    D[cur] = now
    for nex in G[cur]:
        now = dfs(nex,now)
    now += 1
    D2[cur] = now
    return now
now = 0
for i in range(N):
    now = dfs(i,now)
for i in range(N):
    print(i+1,D[i],D2[i])
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 N = int(input()) N int(input()) int input() input list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(lambda x: int(x)-1, input().split()))[2:] (map(lambda x: int(x)-1, input().split())) list map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split 2: 2 G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)] G [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)] D = [-1]*N D [-1]*N [-1] -1 N D2 = [-1]*N D2 [-1]*N [-1] -1 N def dfs(cur, now):
    if D[cur] != -1: return now
    now += 1
    D[cur] = now
    for nex in G[cur]:
        now = dfs(nex,now)
    now += 1
    D2[cur] = now
    return now dfs if D[cur] != -1: return now
     D[cur] != -1 D[cur] D cur -1 now += 1 now 1 D[cur] = now D[cur] D cur now for nex in G[cur]:
        now = dfs(nex,now)
     nex G[cur] G cur now = dfs(nex,now) now dfs(nex,now) dfs nex now now += 1 now 1 D2[cur] = now D2[cur] D2 cur now return now now cur cur now now now = 0 now 0 for i in range(N):
    now = dfs(i,now) i range(N) range N now = dfs(i,now) now dfs(i,now) dfs i now for i in range(N):
    print(i+1,D[i],D2[i]) i range(N) range N print(i+1,D[i],D2[i]) print i+1 i 1 D[i] D i D2[i] D2 i input = sys.stdin.readline sys.stdin.readline input now = 0 0 now D2 = [-1]*N [-1]*N D2 G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)] [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)] G D = [-1]*N [-1]*N D N = int(input()) int(input()) N now = dfs(i,now) dfs(i,now) now def dfs(cur, now):
    if D[cur] != -1: return now
    now += 1
    D[cur] = now
    for nex in G[cur]:
        now = dfs(nex,now)
    now += 1
    D2[cur] = now
    return now def dfs(cur, now):
    if D[cur] != -1: return now
    now += 1
    D[cur] = now
    for nex in G[cur]:
        now = dfs(nex,now)
    now += 1
    D2[cur] = now
    return now dfs
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)]
D = [-1]*N
D2 = [-1]*N
def dfs(cur, now):
    if D[cur] != -1: return now
    now += 1
    D[cur] = now
    for nex in G[cur]:
        now = dfs(nex,now)
    now += 1
    D2[cur] = now
    return now
now = 0
for i in range(N):
    now = dfs(i,now)
for i in range(N):
    print(i+1,D[i],D2[i])

