from sys import stdin
readline=stdin.readline

#入力
n=int(readline())
m=n+1
u,k,v=[0]*m,[0]*m,[0]*m
for i in range(1,m):
    u[i],k[i],*v[i]=map(int,readline().split())

d=[0]*m
f=[0]*m
flags=[False]*m
t=0
def dfs(now):
    global t
    t+=1
    d[now]=t
    flags[now]=True
    for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
    t+=1
    f[now]=t
now=1
while True:
    dfs(now)
    for i in range(1,m):
        if flags[i]==False:
            now=i
            break
    else:
        break

for i in range(1,m):
    print(i,d[i],f[i]) from sys import stdin readline=stdin.readline readline stdin.readline stdin readline n=int(readline()) n int(readline()) int readline() readline m=n+1 m n+1 n 1 u,k,v=[0]*m,[0]*m,[0]*m u [0]*m [0] 0 m k [0]*m [0] 0 m v [0]*m [0] 0 m for i in range(1,m):
    u[i],k[i],*v[i]=map(int,readline().split()) i range(1,m) range 1 m u[i],k[i],*v[i]=map(int,readline().split()) u[i] u i map(int,readline().split()) map int readline().split() ().split () readline split k[i] k i *v[i] v[i] v i d=[0]*m d [0]*m [0] 0 m f=[0]*m f [0]*m [0] 0 m flags=[False]*m flags [False]*m [False] False m t=0 t 0 def dfs(now):
    global t
    t+=1
    d[now]=t
    flags[now]=True
    for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
    t+=1
    f[now]=t dfs global t t+=1 t 1 d[now]=t d[now] d now t flags[now]=True flags[now] flags now True for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
     nex v[now] v now if flags[nex]==False:
            dfs(nex)
     flags[nex]==False flags[nex] flags nex False dfs(nex) dfs nex t+=1 t 1 f[now]=t f[now] f now t now now now=1 now 1 while True:
    dfs(now)
    for i in range(1,m):
        if flags[i]==False:
            now=i
            break
    else:
        break True dfs(now) dfs now for i in range(1,m):
        if flags[i]==False:
            now=i
            break
    else:
        break i range(1,m) range 1 m if flags[i]==False:
            now=i
            break
     flags[i]==False flags[i] flags i False now=i now i break break for i in range(1,m):
    print(i,d[i],f[i]) i range(1,m) range 1 m print(i,d[i],f[i]) print i d[i] d i f[i] f i k,v=[0]*m,[0]*m,[0]*m [0]*m k t=0 0 t now=1 1 now f=[0]*m [0]*m f u,k,v=[0]*m,[0]*m,[0]*m [0]*m u now=i i now readline=stdin.readline stdin.readline readline n=int(readline()) int(readline()) n def dfs(now):
    global t
    t+=1
    d[now]=t
    flags[now]=True
    for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
    t+=1
    f[now]=t def dfs(now):
    global t
    t+=1
    d[now]=t
    flags[now]=True
    for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
    t+=1
    f[now]=t dfs v=[0]*m,[0]*m,[0]*m [0]*m v flags=[False]*m [False]*m flags d=[0]*m [0]*m d m=n+1 n+1 m
from sys import stdin
readline=stdin.readline

#入力
n=int(readline())
m=n+1
u,k,v=[0]*m,[0]*m,[0]*m
for i in range(1,m):
    u[i],k[i],*v[i]=map(int,readline().split())

d=[0]*m
f=[0]*m
flags=[False]*m
t=0
def dfs(now):
    global t
    t+=1
    d[now]=t
    flags[now]=True
    for nex in v[now]:
        if flags[nex]==False:
            dfs(nex)
    t+=1
    f[now]=t
now=1
while True:
    dfs(now)
    for i in range(1,m):
        if flags[i]==False:
            now=i
            break
    else:
        break

for i in range(1,m):
    print(i,d[i],f[i])
