def dfs(u):
    global time
    time+=1
    color[u]='gray'
    d[u]+=time
    for v in xrange(n):
        if m[u][v]!=0 and color[v]=="white":
            dfs(v)
    time+=1
    color[u]="black"
    f[u]+=time
    

n=input()
info=[0]*n
color=["white"]*n
m=[[0]*n for _ in xrange(n)]
d=[0]*n
f=[0]*n
for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
        for j in info[i][2:]:
            m[i][j-1]=j
time=0
for i in xrange(n):
    if color[i]=="white":
        dfs(i)
for i in xrange(n):
    print i+1,d[i],f[i] def dfs(u):
    global time
    time+=1
    color[u]='gray'
    d[u]+=time
    for v in xrange(n):
        if m[u][v]!=0 and color[v]=="white":
            dfs(v)
    time+=1
    color[u]="black"
    f[u]+=time
     dfs global time time+=1 time 1 color[u]='gray' color[u] color u 'gray' d[u]+=time d[u] d u time for v in xrange(n):
        if m[u][v]!=0 and color[v]=="white":
            dfs(v)
     v xrange(n) xrange n if m[u][v]!=0 and color[v]=="white":
            dfs(v)
     m[u][v]!=0 and color[v]=="white" m[u][v]!=0 m[u][v] [u] m u v 0 color[v]=="white" color[v] color v "white" dfs(v) dfs v time+=1 time 1 color[u]="black" color[u] color u "black" f[u]+=time f[u] f u time u u n=input() n input() input info=[0]*n info [0]*n [0] 0 n color=["white"]*n color ["white"]*n ["white"] "white" n [0]*n for _ in xrange(n) for _ in xrange(n) _ xrange(n) xrange n for _ in xrange(n) [0]*n [0] 0 n m=[[0]*n for _ in xrange(n)] m [[0]*n for _ in xrange(n)] d=[0]*n d [0]*n [0] 0 n f=[0]*n f [0]*n [0] 0 n for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
        for j in info[i][2:]:
            m[i][j-1]=j i xrange(n) xrange n info[i]=map(int,raw_input().split()) info[i] info i map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split if info[i][1]==0:
        pass
    else:
        for j in info[i][2:]:
            m[i][j-1]=j info[i][1]==0 info[i][1] [i] info i 1 0 for j in info[i][2:]:
            m[i][j-1]=j j info[i][2:] [i] info i 2: 2 m[i][j-1]=j m[i][j-1] [i] m i j-1 j 1 j time=0 time 0 for i in xrange(n):
    if color[i]=="white":
        dfs(i) i xrange(n) xrange n if color[i]=="white":
        dfs(i) color[i]=="white" color[i] color i "white" dfs(i) dfs i for i in xrange(n):
    print i+1,d[i],f[i] i xrange(n) xrange n print i+1 i 1 d[i] d i f[i] f i m=[[0]*n for _ in xrange(n)] [[0]*n for _ in xrange(n)] m info=[0]*n [0]*n info d=[0]*n [0]*n d time=0 0 time n=input() input() n color=["white"]*n ["white"]*n color f=[0]*n [0]*n f def dfs(u):
    global time
    time+=1
    color[u]='gray'
    d[u]+=time
    for v in xrange(n):
        if m[u][v]!=0 and color[v]=="white":
            dfs(v)
    time+=1
    color[u]="black"
    f[u]+=time
     def dfs(u):
    global time
    time+=1
    color[u]='gray'
    d[u]+=time
    for v in xrange(n):
        if m[u][v]!=0 and color[v]=="white":
            dfs(v)
    time+=1
    color[u]="black"
    f[u]+=time
     dfs
def dfs(u):
    global time
    time+=1
    color[u]='gray'
    d[u]+=time
    for v in xrange(n):
        if m[u][v]!=0 and color[v]=="white":
            dfs(v)
    time+=1
    color[u]="black"
    f[u]+=time
    

n=input()
info=[0]*n
color=["white"]*n
m=[[0]*n for _ in xrange(n)]
d=[0]*n
f=[0]*n
for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
        for j in info[i][2:]:
            m[i][j-1]=j
time=0
for i in xrange(n):
    if color[i]=="white":
        dfs(i)
for i in xrange(n):
    print i+1,d[i],f[i]