n = int(input())
B = [[0 for i in range(n)] for j in range(n)]
chk = [0 for i in range(n)]
s = []
i_array = [0 for i in range(n)]
time = 1
node_start_time = [0 for i in range(n)]
node_finish_time = [0 for i in range(n)]

for i in range(n):
    A = list(map(int,input().split()))
    for j in range(A[1]):
        B[A[0]-1][A[j+2]-1] = 1

for i in range(n):
    if(chk[i] == 1):
        continue
    chk[i] = 1
    node_start_time[i] = time
    time += 1
    s.append(i)
    while(len(s) != 0):
        flag = 0
        v = s[len(s)-1]
        for j in range(i_array[v],n):
            if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                node_start_time[j] = time
                time += 1
                i_array[v] = j+1
                flag = 1
                break
        if(flag == 0):
            s.pop()
            node_finish_time[v] = time
            time += 1

for i in range(n):
    print(i+1,node_start_time[i],node_finish_time[i]) n = int(input()) n int(input()) int input() input [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] B = [[0 for i in range(n)] for j in range(n)] B [[0 for i in range(n)] for j in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 chk = [0 for i in range(n)] chk [0 for i in range(n)] s = [] s [] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 i_array = [0 for i in range(n)] i_array [0 for i in range(n)] time = 1 time 1 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 node_start_time = [0 for i in range(n)] node_start_time [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 node_finish_time = [0 for i in range(n)] node_finish_time [0 for i in range(n)] for i in range(n):
    A = list(map(int,input().split()))
    for j in range(A[1]):
        B[A[0]-1][A[j+2]-1] = 1 i range(n) range n A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split for j in range(A[1]):
        B[A[0]-1][A[j+2]-1] = 1 j range(A[1]) range A[1] A 1 B[A[0]-1][A[j+2]-1] = 1 B[A[0]-1][A[j+2]-1] [A[0]-1] B A[0]-1 A[0] A 0 1 A[j+2]-1 A[j+2] A j+2 j 2 1 1 for i in range(n):
    if(chk[i] == 1):
        continue
    chk[i] = 1
    node_start_time[i] = time
    time += 1
    s.append(i)
    while(len(s) != 0):
        flag = 0
        v = s[len(s)-1]
        for j in range(i_array[v],n):
            if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                node_start_time[j] = time
                time += 1
                i_array[v] = j+1
                flag = 1
                break
        if(flag == 0):
            s.pop()
            node_finish_time[v] = time
            time += 1 i range(n) range n if(chk[i] == 1):
        continue
     chk[i] == 1 chk[i] chk i 1 continue chk[i] = 1 chk[i] chk i 1 node_start_time[i] = time node_start_time[i] node_start_time i time time += 1 time 1 s.append(i) s.append s append i while(len(s) != 0):
        flag = 0
        v = s[len(s)-1]
        for j in range(i_array[v],n):
            if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                node_start_time[j] = time
                time += 1
                i_array[v] = j+1
                flag = 1
                break
        if(flag == 0):
            s.pop()
            node_finish_time[v] = time
            time += 1 len(s) != 0 len(s) len s 0 flag = 0 flag 0 v = s[len(s)-1] v s[len(s)-1] s len(s)-1 len(s) len s 1 for j in range(i_array[v],n):
            if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                node_start_time[j] = time
                time += 1
                i_array[v] = j+1
                flag = 1
                break
         j range(i_array[v],n) range i_array[v] i_array v n if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                node_start_time[j] = time
                time += 1
                i_array[v] = j+1
                flag = 1
                break
         B[v][j] == 1 and chk[j] == 0 B[v][j] == 1 B[v][j] [v] B v j 1 chk[j] == 0 chk[j] chk j 0 chk[j] = 1 chk[j] chk j 1 s.append(j) s.append s append j node_start_time[j] = time node_start_time[j] node_start_time j time time += 1 time 1 i_array[v] = j+1 i_array[v] i_array v j+1 j 1 flag = 1 flag 1 break if(flag == 0):
            s.pop()
            node_finish_time[v] = time
            time += 1 flag == 0 flag 0 s.pop() s.pop s pop node_finish_time[v] = time node_finish_time[v] node_finish_time v time time += 1 time 1 for i in range(n):
    print(i+1,node_start_time[i],node_finish_time[i]) i range(n) range n print(i+1,node_start_time[i],node_finish_time[i]) print i+1 i 1 node_start_time[i] node_start_time i node_finish_time[i] node_finish_time i B = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] B flag = 1 1 flag v = s[len(s)-1] s[len(s)-1] v n = int(input()) int(input()) n node_finish_time = [0 for i in range(n)] [0 for i in range(n)] node_finish_time node_start_time = [0 for i in range(n)] [0 for i in range(n)] node_start_time time += 1 1 time i_array = [0 for i in range(n)] [0 for i in range(n)] i_array A = list(map(int,input().split())) list(map(int,input().split())) A chk = [0 for i in range(n)] [0 for i in range(n)] chk time += 1 1 time time += 1 1 time flag = 0 0 flag time = 1 1 time s = [] [] s
n = int(input())
B = [[0 for i in range(n)] for j in range(n)]
chk = [0 for i in range(n)]
s = []
i_array = [0 for i in range(n)]
time = 1
node_start_time = [0 for i in range(n)]
node_finish_time = [0 for i in range(n)]

for i in range(n):
    A = list(map(int,input().split()))
    for j in range(A[1]):
        B[A[0]-1][A[j+2]-1] = 1

for i in range(n):
    if(chk[i] == 1):
        continue
    chk[i] = 1
    node_start_time[i] = time
    time += 1
    s.append(i)
    while(len(s) != 0):
        flag = 0
        v = s[len(s)-1]
        for j in range(i_array[v],n):
            if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                node_start_time[j] = time
                time += 1
                i_array[v] = j+1
                flag = 1
                break
        if(flag == 0):
            s.pop()
            node_finish_time[v] = time
            time += 1

for i in range(n):
    print(i+1,node_start_time[i],node_finish_time[i])
