n = int(input())
E = [[]]*n

for i in range(n):
    inputs = list(map(int, input().split()))
    if inputs[1]==0:
        continue
    else:
        for j in inputs[2:]:
            E[i] = E[i] + [j-1]

beg = [-1]*n
fin = [-1]*n  

t = 0      
def f(i):
    global t
    #print(i,t)
    t += 1
    beg[i] = t
    for c in E[i]:
        if beg[c]>0:
            continue
        else:
            f(c)
    t+=1
    fin[i] = t
    

for i in range(n):
    if beg[i]<0:
        f(i)
for i in range(n):
    print(i+1, beg[i], fin[i]) n = int(input()) n int(input()) int input() input E = [[]]*n E [[]]*n [[]] [] n for i in range(n):
    inputs = list(map(int, input().split()))
    if inputs[1]==0:
        continue
    else:
        for j in inputs[2:]:
            E[i] = E[i] + [j-1] i range(n) range n inputs = list(map(int, input().split())) inputs list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if inputs[1]==0:
        continue
    else:
        for j in inputs[2:]:
            E[i] = E[i] + [j-1] inputs[1]==0 inputs[1] inputs 1 0 continue for j in inputs[2:]:
            E[i] = E[i] + [j-1] j inputs[2:] inputs 2: 2 E[i] = E[i] + [j-1] E[i] E i E[i] + [j-1] E[i] E i [j-1] j-1 j 1 beg = [-1]*n beg [-1]*n [-1] -1 n fin = [-1]*n fin [-1]*n [-1] -1 n t = 0 t 0 def f(i):
    global t
    #print(i,t)
    t += 1
    beg[i] = t
    for c in E[i]:
        if beg[c]>0:
            continue
        else:
            f(c)
    t+=1
    fin[i] = t
     f global t t += 1 t 1 beg[i] = t beg[i] beg i t for c in E[i]:
        if beg[c]>0:
            continue
        else:
            f(c)
     c E[i] E i if beg[c]>0:
            continue
        else:
            f(c)
     beg[c]>0 beg[c] beg c 0 continue f(c) f c t+=1 t 1 fin[i] = t fin[i] fin i t i i for i in range(n):
    if beg[i]<0:
        f(i) i range(n) range n if beg[i]<0:
        f(i) beg[i]<0 beg[i] beg i 0 f(i) f i for i in range(n):
    print(i+1, beg[i], fin[i]) i range(n) range n print(i+1, beg[i], fin[i]) print i+1 i 1 beg[i] beg i fin[i] fin i E = [[]]*n [[]]*n E beg = [-1]*n [-1]*n beg fin = [-1]*n [-1]*n fin n = int(input()) int(input()) n t = 0 0 t def f(i):
    global t
    #print(i,t)
    t += 1
    beg[i] = t
    for c in E[i]:
        if beg[c]>0:
            continue
        else:
            f(c)
    t+=1
    fin[i] = t
     def f(i):
    global t
    #print(i,t)
    t += 1
    beg[i] = t
    for c in E[i]:
        if beg[c]>0:
            continue
        else:
            f(c)
    t+=1
    fin[i] = t
     f inputs = list(map(int, input().split())) list(map(int, input().split())) inputs
n = int(input())
E = [[]]*n

for i in range(n):
    inputs = list(map(int, input().split()))
    if inputs[1]==0:
        continue
    else:
        for j in inputs[2:]:
            E[i] = E[i] + [j-1]

beg = [-1]*n
fin = [-1]*n  

t = 0      
def f(i):
    global t
    #print(i,t)
    t += 1
    beg[i] = t
    for c in E[i]:
        if beg[c]>0:
            continue
        else:
            f(c)
    t+=1
    fin[i] = t
    

for i in range(n):
    if beg[i]<0:
        f(i)
for i in range(n):
    print(i+1, beg[i], fin[i])
