# coding: utf-8
# Your code here!

import sys
read = sys.stdin.read
readline = sys.stdin.readline


def dfs(G, v, d, f, time):
    time += 1
    d[v] = time

    for e in G[v]:
        if d[e] == 0:
            time = dfs(G, e, d, f, time)

    time += 1
    f[v] = time

    return time


def main():
    n = int(readline())

    E = [[]]
    for _ in range(n):
        u,k,*v = map(int, readline().split())
        E.append(v)

    d = [0] * (n+1)
    f = [0] * (n+1)
    time = 0
    
    for i in range(1,n+1):
        if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
    for i in range(1, n+1):
        print(i, d[i], f[i])


if __name__ == "__main__":
    main()

 import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline def dfs(G, v, d, f, time):
    time += 1
    d[v] = time

    for e in G[v]:
        if d[e] == 0:
            time = dfs(G, e, d, f, time)

    time += 1
    f[v] = time

    return time dfs time += 1 time 1 d[v] = time d[v] d v time for e in G[v]:
        if d[e] == 0:
            time = dfs(G, e, d, f, time)

     e G[v] G v if d[e] == 0:
            time = dfs(G, e, d, f, time)

     d[e] == 0 d[e] d e 0 time = dfs(G, e, d, f, time) time dfs(G, e, d, f, time) dfs G e d f time time += 1 time 1 f[v] = time f[v] f v time return time time G G v v d d f f time time def main():
    n = int(readline())

    E = [[]]
    for _ in range(n):
        u,k,*v = map(int, readline().split())
        E.append(v)

    d = [0] * (n+1)
    f = [0] * (n+1)
    time = 0
    
    for i in range(1,n+1):
        if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
    for i in range(1, n+1):
        print(i, d[i], f[i]) main n = int(readline()) n int(readline()) int readline() readline E = [[]] E [[]] [] for _ in range(n):
        u,k,*v = map(int, readline().split())
        E.append(v)

     _ range(n) range n u,k,*v = map(int, readline().split()) u map(int, readline().split()) map int readline().split() ().split () readline split k *v v E.append(v) E.append E append v d = [0] * (n+1) d [0] * (n+1) [0] 0 n+1 n 1 f = [0] * (n+1) f [0] * (n+1) [0] 0 n+1 n 1 time = 0 time 0 for i in range(1,n+1):
        if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
     i range(1,n+1) range 1 n+1 n 1 if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
     d[i] == 0 d[i] d i 0 time = dfs(E, i, d, f, time) time dfs(E, i, d, f, time) dfs E i d f time for i in range(1, n+1):
        print(i, d[i], f[i]) i range(1, n+1) range 1 n+1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n = int(readline())

    E = [[]]
    for _ in range(n):
        u,k,*v = map(int, readline().split())
        E.append(v)

    d = [0] * (n+1)
    f = [0] * (n+1)
    time = 0
    
    for i in range(1,n+1):
        if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
    for i in range(1, n+1):
        print(i, d[i], f[i]) def main():
    n = int(readline())

    E = [[]]
    for _ in range(n):
        u,k,*v = map(int, readline().split())
        E.append(v)

    d = [0] * (n+1)
    f = [0] * (n+1)
    time = 0
    
    for i in range(1,n+1):
        if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
    for i in range(1, n+1):
        print(i, d[i], f[i]) main def dfs(G, v, d, f, time):
    time += 1
    d[v] = time

    for e in G[v]:
        if d[e] == 0:
            time = dfs(G, e, d, f, time)

    time += 1
    f[v] = time

    return time def dfs(G, v, d, f, time):
    time += 1
    d[v] = time

    for e in G[v]:
        if d[e] == 0:
            time = dfs(G, e, d, f, time)

    time += 1
    f[v] = time

    return time dfs read = sys.stdin.read sys.stdin.read read readline = sys.stdin.readline sys.stdin.readline readline
# coding: utf-8
# Your code here!

import sys
read = sys.stdin.read
readline = sys.stdin.readline


def dfs(G, v, d, f, time):
    time += 1
    d[v] = time

    for e in G[v]:
        if d[e] == 0:
            time = dfs(G, e, d, f, time)

    time += 1
    f[v] = time

    return time


def main():
    n = int(readline())

    E = [[]]
    for _ in range(n):
        u,k,*v = map(int, readline().split())
        E.append(v)

    d = [0] * (n+1)
    f = [0] * (n+1)
    time = 0
    
    for i in range(1,n+1):
        if d[i] == 0:
            time = dfs(E, i, d, f, time)
    
    for i in range(1, n+1):
        print(i, d[i], f[i])


if __name__ == "__main__":
    main()


