n = int(input())

from collections import deque

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)
    
arrive = [-1 for i in range(n+1)]
finish = [-1 for i in range(n+1)]

times = 0

def dfs(v):
    global times
    times += 1
    arrive[v] = times
    stack = [v]
    
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
    return

for i in range(n):
    if arrive[i+1] == -1:
        dfs(i+1)

for j in range(n):
    tmp = [j+1, arrive[j+1], finish[j+1]]
    print(*tmp)
 n = int(input()) n int(input()) int input() input from collections import deque 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 -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) -1 arrive = [-1 for i in range(n+1)] arrive [-1 for i in range(n+1)] -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) -1 finish = [-1 for i in range(n+1)] finish [-1 for i in range(n+1)] times = 0 times 0 def dfs(v):
    global times
    times += 1
    arrive[v] = times
    stack = [v]
    
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
    return dfs global times times += 1 times 1 arrive[v] = times arrive[v] arrive v times stack = [v] stack [v] v while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
     stack v = stack[-1] v stack[-1] stack -1 if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
     graph[v] graph v w = graph[v].popleft() w graph[v].popleft() [v].popleft [v] graph v popleft if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
         arrive[w] == -1 arrive[w] arrive w -1 times += 1 times 1 arrive[w] = times arrive[w] arrive w times stack.append(w) stack.append stack append w times += 1 times 1 finish[v] = times finish[v] finish v times stack.pop() stack.pop stack pop return v v for i in range(n):
    if arrive[i+1] == -1:
        dfs(i+1) i range(n) range n if arrive[i+1] == -1:
        dfs(i+1) arrive[i+1] == -1 arrive[i+1] arrive i+1 i 1 -1 dfs(i+1) dfs i+1 i 1 for j in range(n):
    tmp = [j+1, arrive[j+1], finish[j+1]]
    print(*tmp) j range(n) range n tmp = [j+1, arrive[j+1], finish[j+1]] tmp [j+1, arrive[j+1], finish[j+1]] j+1 j 1 arrive[j+1] arrive j+1 j 1 finish[j+1] finish j+1 j 1 print(*tmp) print *tmp tmp finish = [-1 for i in range(n+1)] [-1 for i in range(n+1)] finish times = 0 0 times tmp = [j+1, arrive[j+1], finish[j+1]] [j+1, arrive[j+1], finish[j+1]] tmp graph = [deque([]) for _ in range(n+1)] [deque([]) for _ in range(n+1)] graph arrive = [-1 for i in range(n+1)] [-1 for i in range(n+1)] arrive u, k, *v = [int(x) for x in input().split()] [int(x) for x in input().split()] u def dfs(v):
    global times
    times += 1
    arrive[v] = times
    stack = [v]
    
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
    return def dfs(v):
    global times
    times += 1
    arrive[v] = times
    stack = [v]
    
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
    return dfs n = int(input()) int(input()) n k, *v = [int(x) for x in input().split()] [int(x) for x in input().split()] k
n = int(input())

from collections import deque

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)
    
arrive = [-1 for i in range(n+1)]
finish = [-1 for i in range(n+1)]

times = 0

def dfs(v):
    global times
    times += 1
    arrive[v] = times
    stack = [v]
    
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive[w] == -1:
                times += 1
                arrive[w] = times
                stack.append(w)
        else:
            times += 1
            finish[v] = times
            stack.pop()
    return

for i in range(n):
    if arrive[i+1] == -1:
        dfs(i+1)

for j in range(n):
    tmp = [j+1, arrive[j+1], finish[j+1]]
    print(*tmp)

