def dfs(v, k):
    if ans[v][1] == 0:
        ans[v][1] = k
    else:
        return k - 1
    for i in d[v]:
        k = dfs(i, k + 1)
    k += 1
    if ans[v][2] == 0:
        ans[v][2] = k
    return k


G = int(input())
vlst = [list(map(int, input().split())) for _ in range(G)]
d = [[] for _ in range(G)]
for i in range(G):
    for j in range(vlst[i][1]):
        d[i].append(vlst[i][2 + j] - 1)
ans = [[_, 0, 0] for _ in range(G)]
k = 1
for i in range(G):
    k = dfs(i, k) + 1
for i in ans:
    print(i[0] + 1, i[1], i[2]) def dfs(v, k):
    if ans[v][1] == 0:
        ans[v][1] = k
    else:
        return k - 1
    for i in d[v]:
        k = dfs(i, k + 1)
    k += 1
    if ans[v][2] == 0:
        ans[v][2] = k
    return k dfs if ans[v][1] == 0:
        ans[v][1] = k
    else:
        return k - 1
     ans[v][1] == 0 ans[v][1] [v] ans v 1 0 ans[v][1] = k ans[v][1] [v] ans v 1 k return k - 1 k - 1 k 1 for i in d[v]:
        k = dfs(i, k + 1)
     i d[v] d v k = dfs(i, k + 1) k dfs(i, k + 1) dfs i k + 1 k 1 k += 1 k 1 if ans[v][2] == 0:
        ans[v][2] = k
     ans[v][2] == 0 ans[v][2] [v] ans v 2 0 ans[v][2] = k ans[v][2] [v] ans v 2 k return k k v v k k G = int(input()) G int(input()) int input() input list(map(int, input().split())) for _ in range(G) for _ in range(G) _ range(G) range G for _ in range(G) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split vlst = [list(map(int, input().split())) for _ in range(G)] vlst [list(map(int, input().split())) for _ in range(G)] [] for _ in range(G) for _ in range(G) _ range(G) range G for _ in range(G) [] d = [[] for _ in range(G)] d [[] for _ in range(G)] for i in range(G):
    for j in range(vlst[i][1]):
        d[i].append(vlst[i][2 + j] - 1) i range(G) range G for j in range(vlst[i][1]):
        d[i].append(vlst[i][2 + j] - 1) j range(vlst[i][1]) range vlst[i][1] [i] vlst i 1 d[i].append(vlst[i][2 + j] - 1) [i].append [i] d i append vlst[i][2 + j] - 1 vlst[i][2 + j] [i] vlst i 2 + j 2 j 1 [_, 0, 0] for _ in range(G) for _ in range(G) _ range(G) range G for _ in range(G) [_, 0, 0] _ 0 0 ans = [[_, 0, 0] for _ in range(G)] ans [[_, 0, 0] for _ in range(G)] k = 1 k 1 for i in range(G):
    k = dfs(i, k) + 1 i range(G) range G k = dfs(i, k) + 1 k dfs(i, k) + 1 dfs(i, k) dfs i k 1 for i in ans:
    print(i[0] + 1, i[1], i[2]) i ans print(i[0] + 1, i[1], i[2]) print i[0] + 1 i[0] i 0 1 i[1] i 1 i[2] i 2 k = 1 1 k d = [[] for _ in range(G)] [[] for _ in range(G)] d G = int(input()) int(input()) G def dfs(v, k):
    if ans[v][1] == 0:
        ans[v][1] = k
    else:
        return k - 1
    for i in d[v]:
        k = dfs(i, k + 1)
    k += 1
    if ans[v][2] == 0:
        ans[v][2] = k
    return k def dfs(v, k):
    if ans[v][1] == 0:
        ans[v][1] = k
    else:
        return k - 1
    for i in d[v]:
        k = dfs(i, k + 1)
    k += 1
    if ans[v][2] == 0:
        ans[v][2] = k
    return k dfs k = dfs(i, k) + 1 dfs(i, k) + 1 k vlst = [list(map(int, input().split())) for _ in range(G)] [list(map(int, input().split())) for _ in range(G)] vlst ans = [[_, 0, 0] for _ in range(G)] [[_, 0, 0] for _ in range(G)] ans
def dfs(v, k):
    if ans[v][1] == 0:
        ans[v][1] = k
    else:
        return k - 1
    for i in d[v]:
        k = dfs(i, k + 1)
    k += 1
    if ans[v][2] == 0:
        ans[v][2] = k
    return k


G = int(input())
vlst = [list(map(int, input().split())) for _ in range(G)]
d = [[] for _ in range(G)]
for i in range(G):
    for j in range(vlst[i][1]):
        d[i].append(vlst[i][2 + j] - 1)
ans = [[_, 0, 0] for _ in range(G)]
k = 1
for i in range(G):
    k = dfs(i, k) + 1
for i in ans:
    print(i[0] + 1, i[1], i[2])
