def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t

def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k)

if __name__ == '__main__':
    main()
 def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t dfs if f[v] >= 0:
        return d,f,t
     f[v] >= 0 f[v] f v 0 return d,f,t return d,f,t d f t t += 1 t 1 d[v] = t d[v] d v t for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
     u vum[v] vum v if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
         d[u] >= 0 d[u] d u 0 continue d,f,t = dfs(vum,u,d,f,t) d dfs(vum,u,d,f,t) dfs vum u d f t f t t += 1 t 1 f[v] = t f[v] f v t return d,f,t return d,f,t d f t vum vum v v d d f f t t def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k) main n = int(input()) n int(input()) int input() input rows = [] rows [] for i in range(n):
        rows.append([int(x) for x in input().split()])

     i range(n) range n int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x rows.append([int(x) for x in input().split()]) rows.append rows append [int(x) for x in input().split()] vum = {} vum {} for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
     v row enumerate(rows) enumerate rows u,k = row[0],row[1] u row[0] row 0 k row[1] row 1 ul = [] ul [] if k > 0:
            for j in row[2:]:
                ul.append(j-1)
         k > 0 k 0 for j in row[2:]:
                ul.append(j-1)
         j row[2:] row 2: 2 ul.append(j-1) ul.append ul append j-1 j 1 vum.update({v:ul}) vum.update vum update {v:ul} v v ul d = [-1]*len(vum) d [-1]*len(vum) [-1] -1 len(vum) len vum f = [-1]*len(vum) f [-1]*len(vum) [-1] -1 len(vum) len vum t = 0 t 0 for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
     v vum d,f,t = dfs(vum,v,d,f,t) d dfs(vum,v,d,f,t) dfs vum v d f t f t for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k) i (j,k) j k enumerate(zip(d,f)) enumerate zip(d,f) zip d f print(i+1,j,k) print i+1 i 1 j k if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k) def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k) main def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t dfs
def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t

def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k)

if __name__ == '__main__':
    main()

