from sys import stdin
input = stdin.readline

def DFS(node):
    global time
    if discoveredtime[node] == -1:
        discoveredtime[node] = time
        time += 1

        for child in childlist[node]:
            DFS(child)
        
        finishedtime[node] = time
        time += 1

N = int(input())

childlist = [None]*(N+1)
for _ in range(N):
    u, k, *v = map(int, input().split())
    childlist[u] = v

discoveredtime = [-1]*(N+1)
finishedtime = [-1]*(N+1)
time = 1

for i in range(1, N+1):
    if discoveredtime[i] == -1:
        DFS(i)

for i in range(1, N+1):
    print(i, discoveredtime[i], finishedtime[i]) from sys import stdin input = stdin.readline input stdin.readline stdin readline def DFS(node):
    global time
    if discoveredtime[node] == -1:
        discoveredtime[node] = time
        time += 1

        for child in childlist[node]:
            DFS(child)
        
        finishedtime[node] = time
        time += 1 DFS global time if discoveredtime[node] == -1:
        discoveredtime[node] = time
        time += 1

        for child in childlist[node]:
            DFS(child)
        
        finishedtime[node] = time
        time += 1 discoveredtime[node] == -1 discoveredtime[node] discoveredtime node -1 discoveredtime[node] = time discoveredtime[node] discoveredtime node time time += 1 time 1 for child in childlist[node]:
            DFS(child)
        
         child childlist[node] childlist node DFS(child) DFS child finishedtime[node] = time finishedtime[node] finishedtime node time time += 1 time 1 node node N = int(input()) N int(input()) int input() input childlist = [None]*(N+1) childlist [None]*(N+1) [None] None N+1 N 1 for _ in range(N):
    u, k, *v = map(int, input().split())
    childlist[u] = v _ range(N) range N u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v childlist[u] = v childlist[u] childlist u v discoveredtime = [-1]*(N+1) discoveredtime [-1]*(N+1) [-1] -1 N+1 N 1 finishedtime = [-1]*(N+1) finishedtime [-1]*(N+1) [-1] -1 N+1 N 1 time = 1 time 1 for i in range(1, N+1):
    if discoveredtime[i] == -1:
        DFS(i) i range(1, N+1) range 1 N+1 N 1 if discoveredtime[i] == -1:
        DFS(i) discoveredtime[i] == -1 discoveredtime[i] discoveredtime i -1 DFS(i) DFS i for i in range(1, N+1):
    print(i, discoveredtime[i], finishedtime[i]) i range(1, N+1) range 1 N+1 N 1 print(i, discoveredtime[i], finishedtime[i]) print i discoveredtime[i] discoveredtime i finishedtime[i] finishedtime i discoveredtime = [-1]*(N+1) [-1]*(N+1) discoveredtime def DFS(node):
    global time
    if discoveredtime[node] == -1:
        discoveredtime[node] = time
        time += 1

        for child in childlist[node]:
            DFS(child)
        
        finishedtime[node] = time
        time += 1 def DFS(node):
    global time
    if discoveredtime[node] == -1:
        discoveredtime[node] = time
        time += 1

        for child in childlist[node]:
            DFS(child)
        
        finishedtime[node] = time
        time += 1 DFS N = int(input()) int(input()) N u, k, *v = map(int, input().split()) map(int, input().split()) u k, *v = map(int, input().split()) map(int, input().split()) k childlist = [None]*(N+1) [None]*(N+1) childlist input = stdin.readline stdin.readline input time = 1 1 time finishedtime = [-1]*(N+1) [-1]*(N+1) finishedtime
from sys import stdin
input = stdin.readline

def DFS(node):
    global time
    if discoveredtime[node] == -1:
        discoveredtime[node] = time
        time += 1

        for child in childlist[node]:
            DFS(child)
        
        finishedtime[node] = time
        time += 1

N = int(input())

childlist = [None]*(N+1)
for _ in range(N):
    u, k, *v = map(int, input().split())
    childlist[u] = v

discoveredtime = [-1]*(N+1)
finishedtime = [-1]*(N+1)
time = 1

for i in range(1, N+1):
    if discoveredtime[i] == -1:
        DFS(i)

for i in range(1, N+1):
    print(i, discoveredtime[i], finishedtime[i])
