n = int(input())
m = [[0 for j in range(n)] for i in range(n)]
color = [0 for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
time = [0]


def dfs(u):
    color[u] = 1
    time[0] += 1
    d[u] = time[0]
    for i in range(n):
        if m[u][i] == 1 and color[i] == 0:
            dfs(i)

    color[u] = 2
    time[0] += 1
    f[u] = time[0]


def main():
    for i in range(n):
        data = list(map(int, input().split()))
        for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

    for i in range(n):
        if color[i] == 0:
            dfs(i)

    for i in range(n):
        print(i+1, d[i], f[i])


if __name__ == '__main__':
    main()
 n = int(input()) n int(input()) int input() input [0 for j in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0 for j in range(n)] m = [[0 for j in range(n)] for i in range(n)] m [[0 for j in range(n)] for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 color = [0 for i in range(n)] color [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] time = [0] time [0] 0 def dfs(u):
    color[u] = 1
    time[0] += 1
    d[u] = time[0]
    for i in range(n):
        if m[u][i] == 1 and color[i] == 0:
            dfs(i)

    color[u] = 2
    time[0] += 1
    f[u] = time[0] dfs color[u] = 1 color[u] color u 1 time[0] += 1 time[0] time 0 1 d[u] = time[0] d[u] d u time[0] time 0 for i in range(n):
        if m[u][i] == 1 and color[i] == 0:
            dfs(i)

     i range(n) range n if m[u][i] == 1 and color[i] == 0:
            dfs(i)

     m[u][i] == 1 and color[i] == 0 m[u][i] == 1 m[u][i] [u] m u i 1 color[i] == 0 color[i] color i 0 dfs(i) dfs i color[u] = 2 color[u] color u 2 time[0] += 1 time[0] time 0 1 f[u] = time[0] f[u] f u time[0] time 0 u u def main():
    for i in range(n):
        data = list(map(int, input().split()))
        for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

    for i in range(n):
        if color[i] == 0:
            dfs(i)

    for i in range(n):
        print(i+1, d[i], f[i]) main for i in range(n):
        data = list(map(int, input().split()))
        for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

     i range(n) range n data = list(map(int, input().split())) data list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

     j range(2, len(data)) range 2 len(data) len data m[data[0]-1][data[j]-1] = 1 m[data[0]-1][data[j]-1] [data[0]-1] m data[0]-1 data[0] data 0 1 data[j]-1 data[j] data j 1 1 for i in range(n):
        if color[i] == 0:
            dfs(i)

     i range(n) range n if color[i] == 0:
            dfs(i)

     color[i] == 0 color[i] color i 0 dfs(i) dfs i for i in range(n):
        print(i+1, d[i], f[i]) i range(n) range n print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    for i in range(n):
        data = list(map(int, input().split()))
        for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

    for i in range(n):
        if color[i] == 0:
            dfs(i)

    for i in range(n):
        print(i+1, d[i], f[i]) def main():
    for i in range(n):
        data = list(map(int, input().split()))
        for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

    for i in range(n):
        if color[i] == 0:
            dfs(i)

    for i in range(n):
        print(i+1, d[i], f[i]) main f = [0 for i in range(n)] [0 for i in range(n)] f d = [0 for i in range(n)] [0 for i in range(n)] d n = int(input()) int(input()) n def dfs(u):
    color[u] = 1
    time[0] += 1
    d[u] = time[0]
    for i in range(n):
        if m[u][i] == 1 and color[i] == 0:
            dfs(i)

    color[u] = 2
    time[0] += 1
    f[u] = time[0] def dfs(u):
    color[u] = 1
    time[0] += 1
    d[u] = time[0]
    for i in range(n):
        if m[u][i] == 1 and color[i] == 0:
            dfs(i)

    color[u] = 2
    time[0] += 1
    f[u] = time[0] dfs color = [0 for i in range(n)] [0 for i in range(n)] color time = [0] [0] time m = [[0 for j in range(n)] for i in range(n)] [[0 for j in range(n)] for i in range(n)] m
n = int(input())
m = [[0 for j in range(n)] for i in range(n)]
color = [0 for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
time = [0]


def dfs(u):
    color[u] = 1
    time[0] += 1
    d[u] = time[0]
    for i in range(n):
        if m[u][i] == 1 and color[i] == 0:
            dfs(i)

    color[u] = 2
    time[0] += 1
    f[u] = time[0]


def main():
    for i in range(n):
        data = list(map(int, input().split()))
        for j in range(2, len(data)):
            m[data[0]-1][data[j]-1] = 1

    for i in range(n):
        if color[i] == 0:
            dfs(i)

    for i in range(n):
        print(i+1, d[i], f[i])


if __name__ == '__main__':
    main()

