n=int(input())
#V[u]=[k,[v],d,f]
V=[[0,[],0,0]]
for i in range(n):
    v=[int(i) for i in input().split(" ")]
    u=v.pop(0)
    k=v.pop(0)
    v.sort()
    V.append([k,v,0,0])


def is_finished(Id):
    k=V[Id][0]
    v=V[Id][1]
    for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
    return -1

time=1

while time<=2*n:
 for i in range(1,n+1):
     if V[i][2]==0:
         cur=i
         log=[i]
         break

 while len(log)>0:
    if V[cur][2]==0:
        V[cur][2]=time
        time+=1


    x=is_finished(cur)
    if x!=-1:
        cur=x
        log.append(cur)
    else:
        try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass
for i in range(1,n+1):
    print(i,V[i][2],V[i][3]) n=int(input()) n int(input()) int input() input V=[[0,[],0,0]] V [[0,[],0,0]] [0,[],0,0] 0 [] 0 0 for i in range(n):
    v=[int(i) for i in input().split(" ")]
    u=v.pop(0)
    k=v.pop(0)
    v.sort()
    V.append([k,v,0,0]) i range(n) range n int(i) for i in input().split(" ") for i in input().split(" ") i input().split(" ") ().split () input split " " for i in input().split(" ") int(i) int i v=[int(i) for i in input().split(" ")] v [int(i) for i in input().split(" ")] u=v.pop(0) u v.pop(0) v.pop v pop 0 k=v.pop(0) k v.pop(0) v.pop v pop 0 v.sort() v.sort v sort V.append([k,v,0,0]) V.append V append [k,v,0,0] k v 0 0 def is_finished(Id):
    k=V[Id][0]
    v=V[Id][1]
    for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
    return -1 is_finished k=V[Id][0] k V[Id][0] [Id] V Id 0 v=V[Id][1] v V[Id][1] [Id] V Id 1 for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
     i range(k) range k if V[v[i]][2]==0:
            return v[i]
     V[v[i]][2]==0 V[v[i]][2] [v[i]] V v[i] v i 2 0 return v[i] v[i] v i return -1 -1 Id Id time=1 time 1 while time<=2*n:
 for i in range(1,n+1):
     if V[i][2]==0:
         cur=i
         log=[i]
         break

 while len(log)>0:
    if V[cur][2]==0:
        V[cur][2]=time
        time+=1


    x=is_finished(cur)
    if x!=-1:
        cur=x
        log.append(cur)
    else:
        try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass time<=2*n time 2*n 2 n for i in range(1,n+1):
     if V[i][2]==0:
         cur=i
         log=[i]
         break

  i range(1,n+1) range 1 n+1 n 1 if V[i][2]==0:
         cur=i
         log=[i]
         break

  V[i][2]==0 V[i][2] [i] V i 2 0 cur=i cur i log=[i] log [i] i break while len(log)>0:
    if V[cur][2]==0:
        V[cur][2]=time
        time+=1


    x=is_finished(cur)
    if x!=-1:
        cur=x
        log.append(cur)
    else:
        try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass len(log)>0 len(log) len log 0 if V[cur][2]==0:
        V[cur][2]=time
        time+=1


     V[cur][2]==0 V[cur][2] [cur] V cur 2 0 V[cur][2]=time V[cur][2] [cur] V cur 2 time time+=1 time 1 x=is_finished(cur) x is_finished(cur) is_finished cur if x!=-1:
        cur=x
        log.append(cur)
    else:
        try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass x!=-1 x -1 cur=x cur x log.append(cur) log.append log append cur try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass except:
            pass log.pop(-1) log.pop log pop -1 V[cur][3]=time V[cur][3] [cur] V cur 3 time time+=1 time 1 if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

             V[cur][3]==V[cur][2] V[cur][3] [cur] V cur 3 V[cur][2] [cur] V cur 2 time+=1 time 1 V[cur][3]+=1 V[cur][3] [cur] V cur 3 1 cur=log[-1] cur log[-1] log -1 for i in range(1,n+1):
    print(i,V[i][2],V[i][3]) i range(1,n+1) range 1 n+1 n 1 print(i,V[i][2],V[i][3]) print i V[i][2] [i] V i 2 V[i][3] [i] V i 3 u=v.pop(0) v.pop(0) u k=v.pop(0) v.pop(0) k V=[[0,[],0,0]] [[0,[],0,0]] V n=int(input()) int(input()) n time+=1 1 time cur=x x cur def is_finished(Id):
    k=V[Id][0]
    v=V[Id][1]
    for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
    return -1 def is_finished(Id):
    k=V[Id][0]
    v=V[Id][1]
    for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
    return -1 is_finished time+=1 1 time time+=1 1 time log=[i] [i] log x=is_finished(cur) is_finished(cur) x v=[int(i) for i in input().split(" ")] [int(i) for i in input().split(" ")] v cur=i i cur time=1 1 time cur=log[-1] log[-1] cur
n=int(input())
#V[u]=[k,[v],d,f]
V=[[0,[],0,0]]
for i in range(n):
    v=[int(i) for i in input().split(" ")]
    u=v.pop(0)
    k=v.pop(0)
    v.sort()
    V.append([k,v,0,0])


def is_finished(Id):
    k=V[Id][0]
    v=V[Id][1]
    for i in range(k):
        if V[v[i]][2]==0:
            return v[i]
    return -1

time=1

while time<=2*n:
 for i in range(1,n+1):
     if V[i][2]==0:
         cur=i
         log=[i]
         break

 while len(log)>0:
    if V[cur][2]==0:
        V[cur][2]=time
        time+=1


    x=is_finished(cur)
    if x!=-1:
        cur=x
        log.append(cur)
    else:
        try:
            log.pop(-1)
            V[cur][3]=time
            time+=1
            if V[cur][3]==V[cur][2]:
                time+=1
                V[cur][3]+=1

            cur=log[-1]
        except:
            pass
for i in range(1,n+1):
    print(i,V[i][2],V[i][3])