def dfs(adjlist,v):
    global d,f,t
    d[v-1]=t
    t+=1
    for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
    f[v-1]=t
    t+=1

n=int(input())
adjlist=[list(map(int,input().split()))[2:] for _ in range(n)]
d=[-1]*n
f=[-1]*n
t=1
for i in range(1,n):
    if d[i-1]<0:
       dfs(adjlist,i)
for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i])) def dfs(adjlist,v):
    global d,f,t
    d[v-1]=t
    t+=1
    for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
    f[v-1]=t
    t+=1 dfs global d,f,t d[v-1]=t d[v-1] d v-1 v 1 t t+=1 t 1 for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
     node adjlist[v-1] adjlist v-1 v 1 if d[node-1]<0 and node>0:
            dfs(adjlist,node)
     d[node-1]<0 and node>0 d[node-1]<0 d[node-1] d node-1 node 1 0 node>0 node 0 dfs(adjlist,node) dfs adjlist node f[v-1]=t f[v-1] f v-1 v 1 t t+=1 t 1 adjlist adjlist v v n=int(input()) n int(input()) int input() input list(map(int,input().split()))[2:] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int,input().split()))[2:] (map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 2: 2 adjlist=[list(map(int,input().split()))[2:] for _ in range(n)] adjlist [list(map(int,input().split()))[2:] for _ in range(n)] d=[-1]*n d [-1]*n [-1] -1 n f=[-1]*n f [-1]*n [-1] -1 n t=1 t 1 for i in range(1,n):
    if d[i-1]<0:
       dfs(adjlist,i) i range(1,n) range 1 n if d[i-1]<0:
       dfs(adjlist,i) d[i-1]<0 d[i-1] d i-1 i 1 0 dfs(adjlist,i) dfs adjlist i for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i])) i range(n) range n print("{} {} {}".format(i+1,d[i],f[i])) print "{} {} {}".format(i+1,d[i],f[i]) "{} {} {}".format "{} {} {}" format i+1 i 1 d[i] d i f[i] f i d=[-1]*n [-1]*n d f=[-1]*n [-1]*n f adjlist=[list(map(int,input().split()))[2:] for _ in range(n)] [list(map(int,input().split()))[2:] for _ in range(n)] adjlist t=1 1 t def dfs(adjlist,v):
    global d,f,t
    d[v-1]=t
    t+=1
    for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
    f[v-1]=t
    t+=1 def dfs(adjlist,v):
    global d,f,t
    d[v-1]=t
    t+=1
    for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
    f[v-1]=t
    t+=1 dfs n=int(input()) int(input()) n
def dfs(adjlist,v):
    global d,f,t
    d[v-1]=t
    t+=1
    for node in adjlist[v-1]:
        if d[node-1]<0 and node>0:
            dfs(adjlist,node)
    f[v-1]=t
    t+=1

n=int(input())
adjlist=[list(map(int,input().split()))[2:] for _ in range(n)]
d=[-1]*n
f=[-1]*n
t=1
for i in range(1,n):
    if d[i-1]<0:
       dfs(adjlist,i)
for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i]))
