from collections import deque

N = int(input())
graph = [deque([]) for _ in range((N + 1))]
for _ in range(N):
    u, k, *v = [int(x) for x in input().split()]
    v.sort()
    for i in v:
        graph[u].append(i)
        
time = 0
arrive_time = [-1] * (N + 1)
finish_time = [-1] * (N + 1)

def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
    return [arrive_time, finish_time]
    
for i in range(N):
    if arrive_time[i + 1] < 0:
        ans = dfs(i + 1)
        
for j in range(N):
    temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
    print(*temp) from collections import deque N = int(input()) N int(input()) int input() input deque([]) for _ in range((N + 1)) for _ in range((N + 1)) _ range((N + 1)) range N + 1 N 1 for _ in range((N + 1)) deque([]) deque [] graph = [deque([]) for _ in range((N + 1))] graph [deque([]) for _ in range((N + 1))] for _ in range(N):
    u, k, *v = [int(x) for x in input().split()]
    v.sort()
    for i in v:
        graph[u].append(i)
         _ range(N) range N int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x u, k, *v = [int(x) for x in input().split()] u [int(x) for x in input().split()] k *v v v.sort() v.sort v sort for i in v:
        graph[u].append(i)
         i v graph[u].append(i) [u].append [u] graph u append i time = 0 time 0 arrive_time = [-1] * (N + 1) arrive_time [-1] * (N + 1) [-1] -1 N + 1 N 1 finish_time = [-1] * (N + 1) finish_time [-1] * (N + 1) [-1] -1 N + 1 N 1 def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
    return [arrive_time, finish_time]
     dfs global time time += 1 time 1 stack = [v] stack [v] v arrive_time[v] = time arrive_time[v] arrive_time v time while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
     stack v = stack[-1] v stack[-1] stack -1 if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
     graph[v] graph v w = graph[v].popleft() w graph[v].popleft() [v].popleft [v] graph v popleft if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
         arrive_time[w] < 0 arrive_time[w] arrive_time w 0 time += 1 time 1 arrive_time[w] = time arrive_time[w] arrive_time w time stack.append(w) stack.append stack append w time += 1 time 1 finish_time[v] = time finish_time[v] finish_time v time stack.pop() stack.pop stack pop return [arrive_time, finish_time] [arrive_time, finish_time] arrive_time finish_time v v for i in range(N):
    if arrive_time[i + 1] < 0:
        ans = dfs(i + 1)
         i range(N) range N if arrive_time[i + 1] < 0:
        ans = dfs(i + 1)
         arrive_time[i + 1] < 0 arrive_time[i + 1] arrive_time i + 1 i 1 0 ans = dfs(i + 1) ans dfs(i + 1) dfs i + 1 i 1 for j in range(N):
    temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
    print(*temp) j range(N) range N temp = [j + 1, ans[0][j + 1], ans[1][j + 1]] temp [j + 1, ans[0][j + 1], ans[1][j + 1]] j + 1 j 1 ans[0][j + 1] [0] ans 0 j + 1 j 1 ans[1][j + 1] [1] ans 1 j + 1 j 1 print(*temp) print *temp temp arrive_time = [-1] * (N + 1) [-1] * (N + 1) arrive_time ans = dfs(i + 1) dfs(i + 1) ans u, k, *v = [int(x) for x in input().split()] [int(x) for x in input().split()] u def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
    return [arrive_time, finish_time]
     def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
    return [arrive_time, finish_time]
     dfs N = int(input()) int(input()) N graph = [deque([]) for _ in range((N + 1))] [deque([]) for _ in range((N + 1))] graph time = 0 0 time temp = [j + 1, ans[0][j + 1], ans[1][j + 1]] [j + 1, ans[0][j + 1], ans[1][j + 1]] temp k, *v = [int(x) for x in input().split()] [int(x) for x in input().split()] k finish_time = [-1] * (N + 1) [-1] * (N + 1) finish_time
from collections import deque

N = int(input())
graph = [deque([]) for _ in range((N + 1))]
for _ in range(N):
    u, k, *v = [int(x) for x in input().split()]
    v.sort()
    for i in v:
        graph[u].append(i)
        
time = 0
arrive_time = [-1] * (N + 1)
finish_time = [-1] * (N + 1)

def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
    return [arrive_time, finish_time]
    
for i in range(N):
    if arrive_time[i + 1] < 0:
        ans = dfs(i + 1)
        
for j in range(N):
    temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
    print(*temp)
