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


V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = sorted(v)
D, F = [-1] * V, [-1] * V
c = 1
for i in range(V):
    if D[i] == -1:
        c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f) def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt dfs D[v] = cnt D[v] D v cnt cnt += 1 cnt 1 for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
     c edge[v] edge v if D[c] == -1:
            cnt = dfs(c, cnt)
     D[c] == -1 D[c] D c -1 cnt = dfs(c, cnt) cnt dfs(c, cnt) dfs c cnt F[v] = cnt F[v] F v cnt cnt += 1 cnt 1 return cnt cnt v v cnt cnt V = int(input()) V int(input()) int input() input [] for _ in range(V) for _ in range(V) _ range(V) range V for _ in range(V) [] edge = [[] for _ in range(V)] edge [[] for _ in range(V)] for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = sorted(v) _ range(V) range V u, _, *v = map(lambda x: int(x)-1, input().split()) u 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 _ *v v edge[u] = sorted(v) edge[u] edge u sorted(v) sorted v D, F = [-1] * V, [-1] * V D [-1] * V [-1] -1 V F [-1] * V [-1] -1 V c = 1 c 1 for i in range(V):
    if D[i] == -1:
        c = dfs(i, c) i range(V) range V if D[i] == -1:
        c = dfs(i, c) D[i] == -1 D[i] D i -1 c = dfs(i, c) c dfs(i, c) dfs i c 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 edge = [[] for _ in range(V)] [[] for _ in range(V)] edge u, _, *v = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) u F = [-1] * V, [-1] * V [-1] * V F c = dfs(i, c) dfs(i, c) c _, *v = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) _ def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt dfs V = int(input()) int(input()) V D, F = [-1] * V, [-1] * V [-1] * V D c = 1 1 c
def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt


V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = sorted(v)
D, F = [-1] * V, [-1] * V
c = 1
for i in range(V):
    if D[i] == -1:
        c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f)