#coding:utf-8
        
def DFS(i,A,d,f,t):
    if d[i-1]:
        return t
    d[i-1]=t
    t+=1
    for j in A[i-1]:
        t=DFS(j,A,d,f,t)
    f[i-1]=t
    t+=1
    return t

if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(list(map(int,input().split(" ")))[2:])
    d=[0]*n
    f=[0]*n
    t=1
    for i in range(n):
        if d[i]==0:
            t=DFS(i+1,A,d,f,t)
    for i in range(n):
        print("{} {} {}".format(i+1,d[i],f[i])) def DFS(i,A,d,f,t):
    if d[i-1]:
        return t
    d[i-1]=t
    t+=1
    for j in A[i-1]:
        t=DFS(j,A,d,f,t)
    f[i-1]=t
    t+=1
    return t DFS if d[i-1]:
        return t
     d[i-1] d i-1 i 1 return t t d[i-1]=t d[i-1] d i-1 i 1 t t+=1 t 1 for j in A[i-1]:
        t=DFS(j,A,d,f,t)
     j A[i-1] A i-1 i 1 t=DFS(j,A,d,f,t) t DFS(j,A,d,f,t) DFS j A d f t f[i-1]=t f[i-1] f i-1 i 1 t t+=1 t 1 return t t i i A A d d f f t t if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(list(map(int,input().split(" ")))[2:])
    d=[0]*n
    f=[0]*n
    t=1
    for i in range(n):
        if d[i]==0:
            t=DFS(i+1,A,d,f,t)
    for i in range(n):
        print("{} {} {}".format(i+1,d[i],f[i])) __name__=="__main__" __name__ "__main__" n=int(input()) n int(input()) int input() input A=[] A [] for i in range(n):
        A.append(list(map(int,input().split(" ")))[2:])
     i range(n) range n A.append(list(map(int,input().split(" ")))[2:]) A.append A append list(map(int,input().split(" ")))[2:] (map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " 2: 2 d=[0]*n d [0]*n [0] 0 n f=[0]*n f [0]*n [0] 0 n t=1 t 1 for i in range(n):
        if d[i]==0:
            t=DFS(i+1,A,d,f,t)
     i range(n) range n if d[i]==0:
            t=DFS(i+1,A,d,f,t)
     d[i]==0 d[i] d i 0 t=DFS(i+1,A,d,f,t) t DFS(i+1,A,d,f,t) DFS i+1 i 1 A d f t 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 A=[] [] A def DFS(i,A,d,f,t):
    if d[i-1]:
        return t
    d[i-1]=t
    t+=1
    for j in A[i-1]:
        t=DFS(j,A,d,f,t)
    f[i-1]=t
    t+=1
    return t def DFS(i,A,d,f,t):
    if d[i-1]:
        return t
    d[i-1]=t
    t+=1
    for j in A[i-1]:
        t=DFS(j,A,d,f,t)
    f[i-1]=t
    t+=1
    return t DFS f=[0]*n [0]*n f n=int(input()) int(input()) n t=DFS(i+1,A,d,f,t) DFS(i+1,A,d,f,t) t d=[0]*n [0]*n d t=1 1 t
#coding:utf-8
        
def DFS(i,A,d,f,t):
    if d[i-1]:
        return t
    d[i-1]=t
    t+=1
    for j in A[i-1]:
        t=DFS(j,A,d,f,t)
    f[i-1]=t
    t+=1
    return t

if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(list(map(int,input().split(" ")))[2:])
    d=[0]*n
    f=[0]*n
    t=1
    for i in range(n):
        if d[i]==0:
            t=DFS(i+1,A,d,f,t)
    for i in range(n):
        print("{} {} {}".format(i+1,d[i],f[i]))