n=int(input())
g=[]
for i in range(n):
    u,k,*varray= map(int,input().split())
    g.append(varray)

time = 1
d= [-1]* n
f= [-1]* n

def dfs(src):
    global time
    d[src]= time
    time+=1
    for i in g[src]:
        if d[i-1]== -1:
            dfs(i-1)
    f[src]= time
    time+=1

for i in range(n):
    if d[i]== -1:
        dfs(i)
for i in range(n):
    print(i+1,d[i],f[i]) n=int(input()) n int(input()) int input() input g=[] g [] for i in range(n):
    u,k,*varray= map(int,input().split())
    g.append(varray) i range(n) range n u,k,*varray= map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *varray varray g.append(varray) g.append g append varray time = 1 time 1 d= [-1]* n d [-1]* n [-1] -1 n f= [-1]* n f [-1]* n [-1] -1 n def dfs(src):
    global time
    d[src]= time
    time+=1
    for i in g[src]:
        if d[i-1]== -1:
            dfs(i-1)
    f[src]= time
    time+=1 dfs global time d[src]= time d[src] d src time time+=1 time 1 for i in g[src]:
        if d[i-1]== -1:
            dfs(i-1)
     i g[src] g src if d[i-1]== -1:
            dfs(i-1)
     d[i-1]== -1 d[i-1] d i-1 i 1 -1 dfs(i-1) dfs i-1 i 1 f[src]= time f[src] f src time time+=1 time 1 src src for i in range(n):
    if d[i]== -1:
        dfs(i) i range(n) range n if d[i]== -1:
        dfs(i) d[i]== -1 d[i] d i -1 dfs(i) dfs i for i in range(n):
    print(i+1,d[i],f[i]) 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 def dfs(src):
    global time
    d[src]= time
    time+=1
    for i in g[src]:
        if d[i-1]== -1:
            dfs(i-1)
    f[src]= time
    time+=1 def dfs(src):
    global time
    d[src]= time
    time+=1
    for i in g[src]:
        if d[i-1]== -1:
            dfs(i-1)
    f[src]= time
    time+=1 dfs g=[] [] g time = 1 1 time n=int(input()) int(input()) n u,k,*varray= map(int,input().split()) map(int,input().split()) u k,*varray= map(int,input().split()) map(int,input().split()) k f= [-1]* n [-1]* n f d= [-1]* n [-1]* n d
n=int(input())
g=[]
for i in range(n):
    u,k,*varray= map(int,input().split())
    g.append(varray)

time = 1
d= [-1]* n
f= [-1]* n

def dfs(src):
    global time
    d[src]= time
    time+=1
    for i in g[src]:
        if d[i-1]== -1:
            dfs(i-1)
    f[src]= time
    time+=1

for i in range(n):
    if d[i]== -1:
        dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])
