n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
    u, k, *v = map(int, input().split())
    u -= 1
    G[u].extend(v)
seen = [False] * n
d = [-1] * n
f = [-1] * n
t = 1

def dfs(v):
    global t
#     print(v+1, t)
    d[v] = t
    t += 1
    seen[v] = True
    for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
    f[v] = t
    t += 1
    return t

def main():
#     todo = []
#     seen[0] = True
    for i in range(n):
        if not seen[i]:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])
#     print(G)

if __name__ == "__main__":
    main() n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] G = [[] for _ in range(n)] G [[] for _ in range(n)] for _ in range(n):
    u, k, *v = map(int, input().split())
    u -= 1
    G[u].extend(v) _ range(n) range n u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v u -= 1 u 1 G[u].extend(v) [u].extend [u] G u extend v seen = [False] * n seen [False] * n [False] False n d = [-1] * n d [-1] * n [-1] -1 n f = [-1] * n f [-1] * n [-1] -1 n t = 1 t 1 def dfs(v):
    global t
#     print(v+1, t)
    d[v] = t
    t += 1
    seen[v] = True
    for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
    f[v] = t
    t += 1
    return t dfs global t d[v] = t d[v] d v t t += 1 t 1 seen[v] = True seen[v] seen v True for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
     next_v G[v] G v next_v -= 1 next_v 1 if not seen[next_v]:
            t = dfs(next_v)
     not seen[next_v] seen[next_v] seen next_v t = dfs(next_v) t dfs(next_v) dfs next_v f[v] = t f[v] f v t t += 1 t 1 return t t v v def main():
#     todo = []
#     seen[0] = True
    for i in range(n):
        if not seen[i]:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])
#     print(G) main for i in range(n):
        if not seen[i]:
            dfs(i)
     i range(n) range n if not seen[i]:
            dfs(i)
     not seen[i] seen[i] seen i dfs(i) dfs i for i in range(n):
        print(i+1, d[i], f[i])
#     print(G) 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 dfs(v):
    global t
#     print(v+1, t)
    d[v] = t
    t += 1
    seen[v] = True
    for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
    f[v] = t
    t += 1
    return t def dfs(v):
    global t
#     print(v+1, t)
    d[v] = t
    t += 1
    seen[v] = True
    for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
    f[v] = t
    t += 1
    return t dfs G = [[] for _ in range(n)] [[] for _ in range(n)] G seen = [False] * n [False] * n seen def main():
#     todo = []
#     seen[0] = True
    for i in range(n):
        if not seen[i]:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])
#     print(G) def main():
#     todo = []
#     seen[0] = True
    for i in range(n):
        if not seen[i]:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])
#     print(G) main n = int(input()) int(input()) n d = [-1] * n [-1] * n d f = [-1] * n [-1] * n f k, *v = map(int, input().split()) map(int, input().split()) k u -= 1 1 u u, k, *v = map(int, input().split()) map(int, input().split()) u t = 1 1 t
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
    u, k, *v = map(int, input().split())
    u -= 1
    G[u].extend(v)
seen = [False] * n
d = [-1] * n
f = [-1] * n
t = 1

def dfs(v):
    global t
#     print(v+1, t)
    d[v] = t
    t += 1
    seen[v] = True
    for next_v in G[v]:
        next_v -= 1
        if not seen[next_v]:
            t = dfs(next_v)
    f[v] = t
    t += 1
    return t

def main():
#     todo = []
#     seen[0] = True
    for i in range(n):
        if not seen[i]:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])
#     print(G)

if __name__ == "__main__":
    main()
