def dfs(i):
    global t
    t += 1
    D[i] = t
    for e in es[i]:
        if D[e] == 0:
            dfs(e)
    t += 1
    F[i] = t


if __name__ == "__main__":
    N = int(input())
    es = [[] for _ in range(N+1)]
    for _ in range(N):
        ipts = [int(ipt) for ipt in input().split()]
        if ipts[1] > 0:
            es[ipts[0]] = ipts[2:]
    D = [0 for _ in range(N+1)]
    F = [0 for _ in range(N+1)]
    t = 0
    for i in range(1, N+1):
        if D[i] == 0:
            dfs(i)
    for i in range(1, N+1):
        print(i, D[i], F[i]) def dfs(i):
    global t
    t += 1
    D[i] = t
    for e in es[i]:
        if D[e] == 0:
            dfs(e)
    t += 1
    F[i] = t dfs global t t += 1 t 1 D[i] = t D[i] D i t for e in es[i]:
        if D[e] == 0:
            dfs(e)
     e es[i] es i if D[e] == 0:
            dfs(e)
     D[e] == 0 D[e] D e 0 dfs(e) dfs e t += 1 t 1 F[i] = t F[i] F i t i i if __name__ == "__main__":
    N = int(input())
    es = [[] for _ in range(N+1)]
    for _ in range(N):
        ipts = [int(ipt) for ipt in input().split()]
        if ipts[1] > 0:
            es[ipts[0]] = ipts[2:]
    D = [0 for _ in range(N+1)]
    F = [0 for _ in range(N+1)]
    t = 0
    for i in range(1, N+1):
        if D[i] == 0:
            dfs(i)
    for i in range(1, N+1):
        print(i, D[i], F[i]) __name__ == "__main__" __name__ "__main__" N = int(input()) N int(input()) int input() input [] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [] es = [[] for _ in range(N+1)] es [[] for _ in range(N+1)] for _ in range(N):
        ipts = [int(ipt) for ipt in input().split()]
        if ipts[1] > 0:
            es[ipts[0]] = ipts[2:]
     _ range(N) range N int(ipt) for ipt in input().split() for ipt in input().split() ipt input().split() ().split () input split for ipt in input().split() int(ipt) int ipt ipts = [int(ipt) for ipt in input().split()] ipts [int(ipt) for ipt in input().split()] if ipts[1] > 0:
            es[ipts[0]] = ipts[2:]
     ipts[1] > 0 ipts[1] ipts 1 0 es[ipts[0]] = ipts[2:] es[ipts[0]] es ipts[0] ipts 0 ipts[2:] ipts 2: 2 0 for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) 0 D = [0 for _ in range(N+1)] D [0 for _ in range(N+1)] 0 for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) 0 F = [0 for _ in range(N+1)] F [0 for _ in range(N+1)] t = 0 t 0 for i in range(1, N+1):
        if D[i] == 0:
            dfs(i)
     i range(1, N+1) range 1 N+1 N 1 if D[i] == 0:
            dfs(i)
     D[i] == 0 D[i] D i 0 dfs(i) dfs i 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 ipts = [int(ipt) for ipt in input().split()] [int(ipt) for ipt in input().split()] ipts F = [0 for _ in range(N+1)] [0 for _ in range(N+1)] F N = int(input()) int(input()) N D = [0 for _ in range(N+1)] [0 for _ in range(N+1)] D def dfs(i):
    global t
    t += 1
    D[i] = t
    for e in es[i]:
        if D[e] == 0:
            dfs(e)
    t += 1
    F[i] = t def dfs(i):
    global t
    t += 1
    D[i] = t
    for e in es[i]:
        if D[e] == 0:
            dfs(e)
    t += 1
    F[i] = t dfs es = [[] for _ in range(N+1)] [[] for _ in range(N+1)] es t = 0 0 t
def dfs(i):
    global t
    t += 1
    D[i] = t
    for e in es[i]:
        if D[e] == 0:
            dfs(e)
    t += 1
    F[i] = t


if __name__ == "__main__":
    N = int(input())
    es = [[] for _ in range(N+1)]
    for _ in range(N):
        ipts = [int(ipt) for ipt in input().split()]
        if ipts[1] > 0:
            es[ipts[0]] = ipts[2:]
    D = [0 for _ in range(N+1)]
    F = [0 for _ in range(N+1)]
    t = 0
    for i in range(1, N+1):
        if D[i] == 0:
            dfs(i)
    for i in range(1, N+1):
        print(i, D[i], F[i])
