# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_B

G = {}
d = {}
f = {}
used = set()
t = 1


def dfs(cur):
    global G, d, f, t

    used.add(cur)
    d[cur] = t

    for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
    t += 1
    f[cur] = t


if __name__ == "__main__":
    N = int(input())

    for _ in range(N):
        u, k, *V = list(map(int, input().split()))
        G[u] = V

    for i in range(1, N+1):
        if i not in used:
            dfs(i)
            t += 1

    for i in G.keys():
        print(i, d[i], f[i])
 G = {} G {} d = {} d {} f = {} f {} used = set() used set() set t = 1 t 1 def dfs(cur):
    global G, d, f, t

    used.add(cur)
    d[cur] = t

    for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
    t += 1
    f[cur] = t dfs global G, d, f, t used.add(cur) used.add used add cur d[cur] = t d[cur] d cur t for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
     i G[cur] G cur if i in used:
            continue
         i in used i used continue t += 1 t 1 dfs(i) dfs i t += 1 t 1 f[cur] = t f[cur] f cur t cur cur if __name__ == "__main__":
    N = int(input())

    for _ in range(N):
        u, k, *V = list(map(int, input().split()))
        G[u] = V

    for i in range(1, N+1):
        if i not in used:
            dfs(i)
            t += 1

    for i in G.keys():
        print(i, d[i], f[i]) __name__ == "__main__" __name__ "__main__" N = int(input()) N int(input()) int input() input for _ in range(N):
        u, k, *V = list(map(int, input().split()))
        G[u] = V

     _ range(N) range N u, k, *V = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *V V G[u] = V G[u] G u V for i in range(1, N+1):
        if i not in used:
            dfs(i)
            t += 1

     i range(1, N+1) range 1 N+1 N 1 if i not in used:
            dfs(i)
            t += 1

     i not in used i used dfs(i) dfs i t += 1 t 1 for i in G.keys():
        print(i, d[i], f[i]) i G.keys() G.keys G keys print(i, d[i], f[i]) print i d[i] d i f[i] f i G = {} {} G t += 1 1 t f = {} {} f d = {} {} d def dfs(cur):
    global G, d, f, t

    used.add(cur)
    d[cur] = t

    for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
    t += 1
    f[cur] = t def dfs(cur):
    global G, d, f, t

    used.add(cur)
    d[cur] = t

    for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
    t += 1
    f[cur] = t dfs k, *V = list(map(int, input().split())) list(map(int, input().split())) k N = int(input()) int(input()) N u, k, *V = list(map(int, input().split())) list(map(int, input().split())) u used = set() set() used t = 1 1 t
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_B

G = {}
d = {}
f = {}
used = set()
t = 1


def dfs(cur):
    global G, d, f, t

    used.add(cur)
    d[cur] = t

    for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
    t += 1
    f[cur] = t


if __name__ == "__main__":
    N = int(input())

    for _ in range(N):
        u, k, *V = list(map(int, input().split()))
        G[u] = V

    for i in range(1, N+1):
        if i not in used:
            dfs(i)
            t += 1

    for i in G.keys():
        print(i, d[i], f[i])

