def DFS(G):
    ans = [0] + [[0,0,0] for _ in range(len(G))]
    def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
    for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
    return ans[1:]


if __name__=='__main__':
    n = int(input())
    G = [list(map(int,input().split())) for _ in range(n)]
    for out in DFS(G): print(*out) def DFS(G):
    ans = [0] + [[0,0,0] for _ in range(len(G))]
    def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
    for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
    return ans[1:] DFS [0,0,0] for _ in range(len(G)) for _ in range(len(G)) _ range(len(G)) range len(G) len G for _ in range(len(G)) [0,0,0] 0 0 0 ans = [0] + [[0,0,0] for _ in range(len(G))] ans [0] + [[0,0,0] for _ in range(len(G))] [0] 0 [[0,0,0] for _ in range(len(G))] def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
     main ans[0] += 1 ans[0] ans 0 1 ans[i] = [i, ans[0], ans[0]] ans[i] ans i [i, ans[0], ans[0]] i ans[0] ans 0 ans[0] ans 0 for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
         j sorted(G[i-1][2:]) sorted G[i-1][2:] [i-1] G i-1 i 1 2: 2 if ans[j][0] == 0: main(G,j)
         ans[j][0] == 0 ans[j][0] [j] ans j 0 0 ans[0] += 1 ans[0] ans 0 1 ans[i][2] = ans[0] ans[i][2] [i] ans i 2 ans[0] ans 0 G G i i for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
     u G if ans[u[0]][0] == 0: main(G,u[0])
     ans[u[0]][0] == 0 ans[u[0]][0] [u[0]] ans u[0] u 0 0 0 return ans[1:] ans[1:] ans 1: 1 G G if __name__=='__main__':
    n = int(input())
    G = [list(map(int,input().split())) for _ in range(n)]
    for out in DFS(G): print(*out) __name__=='__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input list(map(int,input().split())) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split G = [list(map(int,input().split())) for _ in range(n)] G [list(map(int,input().split())) for _ in range(n)] for out in DFS(G): print(*out) out DFS(G) DFS G G = [list(map(int,input().split())) for _ in range(n)] [list(map(int,input().split())) for _ in range(n)] G n = int(input()) int(input()) n def DFS(G):
    ans = [0] + [[0,0,0] for _ in range(len(G))]
    def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
    for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
    return ans[1:] def DFS(G):
    ans = [0] + [[0,0,0] for _ in range(len(G))]
    def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
    for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
    return ans[1:] DFS
def DFS(G):
    ans = [0] + [[0,0,0] for _ in range(len(G))]
    def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
    for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
    return ans[1:]


if __name__=='__main__':
    n = int(input())
    G = [list(map(int,input().split())) for _ in range(n)]
    for out in DFS(G): print(*out)