T = [0]

def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0]


n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
    if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0]
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"]) T = [0] T [0] 0 def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0] curserch T[0] = T[0]+1 T[0] T 0 T[0]+1 T[0] T 0 1 P[k]["d"] = T[0] P[k]["d"] [k] P k "d" T[0] T 0 for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0] i range(1,n+1) range 1 n+1 n 1 if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0] N[k][i]==1 and P[i]["d"]==0 N[k][i]==1 N[k][i] [k] N k i 1 P[i]["d"]==0 P[i]["d"] [i] P i "d" 0 curserch(N,i,T,P,n) curserch N i T P n T[0] = T[0]+1 T[0] T 0 T[0]+1 T[0] T 0 1 P[i]["f"]=T[0] P[i]["f"] [i] P i "f" T[0] T 0 N N k k T T P P n n n = int(input()) n int(input()) int input() input [0 for j in range(n+1)] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [0 for j in range(n+1)] A = [[0 for j in range(n+1)] for i in range(n+1)] A [[0 for j in range(n+1)] for i in range(n+1)] for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1 i range(n) range n vec = input().split() vec input().split() ().split () input split u = int(vec[0]) u int(vec[0]) int vec[0] vec 0 k = int(vec[1]) k int(vec[1]) int vec[1] vec 1 nodes = vec[2:] nodes vec[2:] vec 2: 2 for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1 i range(int(k)) range int(k) int k v = int(nodes[i]) v int(nodes[i]) int nodes[i] nodes i A[u][v] = 1 A[u][v] [u] A u v 1 {"d":0} for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) {"d":0} "d" "d" 0 P=[{"d":0} for i in range(n+1)] P [{"d":0} for i in range(n+1)] for i in range(1,n+1):
    if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0] i range(1,n+1) range 1 n+1 n 1 if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0] P[i]["d"]==0 P[i]["d"] [i] P i "d" 0 curserch(A,i,T,P,n) curserch A i T P n T[0] = T[0]+1 T[0] T 0 T[0]+1 T[0] T 0 1 P[i]["f"]=T[0] P[i]["f"] [i] P i "f" T[0] T 0 for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"]) i range(1,n+1) range 1 n+1 n 1 print(i,P[i]["d"],P[i]["f"]) print i P[i]["d"] [i] P i "d" P[i]["f"] [i] P i "f" vec = input().split() input().split() vec v = int(nodes[i]) int(nodes[i]) v def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0] def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0] curserch T = [0] [0] T P=[{"d":0} for i in range(n+1)] [{"d":0} for i in range(n+1)] P A = [[0 for j in range(n+1)] for i in range(n+1)] [[0 for j in range(n+1)] for i in range(n+1)] A n = int(input()) int(input()) n u = int(vec[0]) int(vec[0]) u k = int(vec[1]) int(vec[1]) k nodes = vec[2:] vec[2:] nodes
T = [0]

def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0]


n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
    if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0]
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"])