n=int(input())
adj=[]
for i in range(n):
      adj.append(list(map(int, input().split())))

edge=[[0 for i2 in range(n)]for i1 in range(n)]

#??£??\???????????????

for i in range(n):
    for j in range(adj[i][1]):
        edge[i][adj[i][j+2]-1]=1


time=1
discover=[0 for i in range(n)]
final=[0 for i in range(n)]
stack=[]

def dfs(id,time):
    for i in range(n):
        c=0
        if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
    if c==0:
        if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time)

discover[0]=time
stack.append(0)
dfs(0,time+1)


for i in range(n):
    if discover[i]==0:
        discover[i]=final[0]+1
        stack.append(i)
        dfs(i,final[0]+2)
        break

for i in range(n):
    print(i+1,discover[i],final[i]) n=int(input()) n int(input()) int input() input adj=[] adj [] for i in range(n):
      adj.append(list(map(int, input().split()))) i range(n) range n adj.append(list(map(int, input().split()))) adj.append adj append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [0 for i2 in range(n)]for i1 in range(n) for i1 in range(n) i1 range(n) range n for i1 in range(n) [0 for i2 in range(n)] edge=[[0 for i2 in range(n)]for i1 in range(n)] edge [[0 for i2 in range(n)]for i1 in range(n)] for i in range(n):
    for j in range(adj[i][1]):
        edge[i][adj[i][j+2]-1]=1 i range(n) range n for j in range(adj[i][1]):
        edge[i][adj[i][j+2]-1]=1 j range(adj[i][1]) range adj[i][1] [i] adj i 1 edge[i][adj[i][j+2]-1]=1 edge[i][adj[i][j+2]-1] [i] edge i adj[i][j+2]-1 adj[i][j+2] [i] adj i j+2 j 2 1 1 time=1 time 1 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 discover=[0 for i in range(n)] discover [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 final=[0 for i in range(n)] final [0 for i in range(n)] stack=[] stack [] def dfs(id,time):
    for i in range(n):
        c=0
        if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
    if c==0:
        if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time) dfs for i in range(n):
        c=0
        if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
     i range(n) range n c=0 c 0 if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
     edge[id][i]==1 and discover[i]==0 edge[id][i]==1 edge[id][i] [id] edge id i 1 discover[i]==0 discover[i] discover i 0 stack.append(id) stack.append stack append id discover[i]=time discover[i] discover i time c+=1 c 1 dfs(i,time+1) dfs i time+1 time 1 if c==0:
        if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time) c==0 c 0 if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time) len(stack)>0 len(stack) len stack 0 if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time) final[id]==0 final[id] final id 0 final[id] = time final[id] final id time dfs(stack.pop(), time + 1) dfs stack.pop() stack.pop stack pop time + 1 time 1 dfs(stack.pop(),time) dfs stack.pop() stack.pop stack pop time id id time time discover[0]=time discover[0] discover 0 time stack.append(0) stack.append stack append 0 dfs(0,time+1) dfs 0 time+1 time 1 for i in range(n):
    if discover[i]==0:
        discover[i]=final[0]+1
        stack.append(i)
        dfs(i,final[0]+2)
        break i range(n) range n if discover[i]==0:
        discover[i]=final[0]+1
        stack.append(i)
        dfs(i,final[0]+2)
        break discover[i]==0 discover[i] discover i 0 discover[i]=final[0]+1 discover[i] discover i final[0]+1 final[0] final 0 1 stack.append(i) stack.append stack append i dfs(i,final[0]+2) dfs i final[0]+2 final[0] final 0 2 break for i in range(n):
    print(i+1,discover[i],final[i]) i range(n) range n print(i+1,discover[i],final[i]) print i+1 i 1 discover[i] discover i final[i] final i final=[0 for i in range(n)] [0 for i in range(n)] final stack=[] [] stack edge=[[0 for i2 in range(n)]for i1 in range(n)] [[0 for i2 in range(n)]for i1 in range(n)] edge def dfs(id,time):
    for i in range(n):
        c=0
        if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
    if c==0:
        if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time) def dfs(id,time):
    for i in range(n):
        c=0
        if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
    if c==0:
        if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time) dfs n=int(input()) int(input()) n time=1 1 time discover=[0 for i in range(n)] [0 for i in range(n)] discover adj=[] [] adj
n=int(input())
adj=[]
for i in range(n):
      adj.append(list(map(int, input().split())))

edge=[[0 for i2 in range(n)]for i1 in range(n)]

#??£??\???????????????

for i in range(n):
    for j in range(adj[i][1]):
        edge[i][adj[i][j+2]-1]=1


time=1
discover=[0 for i in range(n)]
final=[0 for i in range(n)]
stack=[]

def dfs(id,time):
    for i in range(n):
        c=0
        if edge[id][i]==1 and discover[i]==0:
            stack.append(id)
            discover[i]=time
            c+=1
            #print(discover,final,i,stack)
            dfs(i,time+1)
        else:
            pass
    if c==0:
        if len(stack)>0:
            if final[id]==0:
                final[id] = time
                #print("back",discover,final,id,stack)
                dfs(stack.pop(), time + 1)
            else:
                #print("back", discover, final, id, stack)
                dfs(stack.pop(),time)

discover[0]=time
stack.append(0)
dfs(0,time+1)


for i in range(n):
    if discover[i]==0:
        discover[i]=final[0]+1
        stack.append(i)
        dfs(i,final[0]+2)
        break

for i in range(n):
    print(i+1,discover[i],final[i])