def dfs(i, cnt):
    D[i] = cnt
    cnt += 1
    for c in v[i]:
        if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
    F[i] = cnt
    cnt += 1
    return cnt


N = int(input())
g = [0]*N
k = [0]*N
v = [[] for _ in range(N)]
for i in range(N):
    tmp = list(map(int, input().split()))
    g[i] = tmp[0]
    k[i] = tmp[1]
    if k[i] != 0:
        v[i] = sorted(tmp[2:])

D = [-1] * N
F = [-1] * N
cnt = 1
for i in range(N):
    if D[i] == -1:
        cnt = dfs(i, cnt)

for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f)
 def dfs(i, cnt):
    D[i] = cnt
    cnt += 1
    for c in v[i]:
        if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
    F[i] = cnt
    cnt += 1
    return cnt dfs D[i] = cnt D[i] D i cnt cnt += 1 cnt 1 for c in v[i]:
        if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
     c v[i] v i if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
     D[c-1] == -1 D[c-1] D c-1 c 1 -1 cnt = dfs(c-1, cnt) cnt dfs(c-1, cnt) dfs c-1 c 1 cnt F[i] = cnt F[i] F i cnt cnt += 1 cnt 1 return cnt cnt i i cnt cnt N = int(input()) N int(input()) int input() input g = [0]*N g [0]*N [0] 0 N k = [0]*N k [0]*N [0] 0 N [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] v = [[] for _ in range(N)] v [[] for _ in range(N)] for i in range(N):
    tmp = list(map(int, input().split()))
    g[i] = tmp[0]
    k[i] = tmp[1]
    if k[i] != 0:
        v[i] = sorted(tmp[2:]) i range(N) range N tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split g[i] = tmp[0] g[i] g i tmp[0] tmp 0 k[i] = tmp[1] k[i] k i tmp[1] tmp 1 if k[i] != 0:
        v[i] = sorted(tmp[2:]) k[i] != 0 k[i] k i 0 v[i] = sorted(tmp[2:]) v[i] v i sorted(tmp[2:]) sorted tmp[2:] tmp 2: 2 D = [-1] * N D [-1] * N [-1] -1 N F = [-1] * N F [-1] * N [-1] -1 N cnt = 1 cnt 1 for i in range(N):
    if D[i] == -1:
        cnt = dfs(i, cnt) i range(N) range N if D[i] == -1:
        cnt = dfs(i, cnt) D[i] == -1 D[i] D i -1 cnt = dfs(i, cnt) cnt dfs(i, cnt) dfs i cnt for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f) i (d, f) d f enumerate(zip(D, F)) enumerate zip(D, F) zip D F print(i+1, d, f) print i+1 i 1 d f def dfs(i, cnt):
    D[i] = cnt
    cnt += 1
    for c in v[i]:
        if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
    F[i] = cnt
    cnt += 1
    return cnt def dfs(i, cnt):
    D[i] = cnt
    cnt += 1
    for c in v[i]:
        if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
    F[i] = cnt
    cnt += 1
    return cnt dfs k = [0]*N [0]*N k v = [[] for _ in range(N)] [[] for _ in range(N)] v N = int(input()) int(input()) N F = [-1] * N [-1] * N F cnt = 1 1 cnt D = [-1] * N [-1] * N D cnt = dfs(i, cnt) dfs(i, cnt) cnt g = [0]*N [0]*N g tmp = list(map(int, input().split())) list(map(int, input().split())) tmp
def dfs(i, cnt):
    D[i] = cnt
    cnt += 1
    for c in v[i]:
        if D[c-1] == -1:
            cnt = dfs(c-1, cnt)
    F[i] = cnt
    cnt += 1
    return cnt


N = int(input())
g = [0]*N
k = [0]*N
v = [[] for _ in range(N)]
for i in range(N):
    tmp = list(map(int, input().split()))
    g[i] = tmp[0]
    k[i] = tmp[1]
    if k[i] != 0:
        v[i] = sorted(tmp[2:])

D = [-1] * N
F = [-1] * N
cnt = 1
for i in range(N):
    if D[i] == -1:
        cnt = dfs(i, cnt)

for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f)

