import sys
input = sys.stdin.readline
from collections import deque

n = int(input())
graph = {i: deque() for i in range(1, 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)
        #graph[i].append(u)

seen = [0]*(n+1)
stack = []
time = 0
seentime = [0]*(n+1)
donetime = [0]*(n+1)

def dfs(j):
    global time
    seen[j] = 1
    time += 1
    seentime[j] = time
    stack.append(j)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO  = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time

for j in range(1, n+1):
    if seen[j]:
        continue
    dfs(j)

for k, a, b in zip(range(1, n+1), seentime[1:], donetime[1:]):
    print(k, a, b) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import deque n = int(input()) n int(input()) int input() input i: deque() for i in range(1, n+1) for i in range(1, n+1) i range(1, n+1) range 1 n+1 n 1 for i in range(1, n+1) i deque() deque graph = {i: deque() for i in range(1, n+1)} graph {i: deque() for i in range(1, 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)
        #graph[i].append(u) _ 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)
        #graph[i].append(u) i v graph[u].append(i) [u].append [u] graph u append i seen = [0]*(n+1) seen [0]*(n+1) [0] 0 n+1 n 1 stack = [] stack [] time = 0 time 0 seentime = [0]*(n+1) seentime [0]*(n+1) [0] 0 n+1 n 1 donetime = [0]*(n+1) donetime [0]*(n+1) [0] 0 n+1 n 1 def dfs(j):
    global time
    seen[j] = 1
    time += 1
    seentime[j] = time
    stack.append(j)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO  = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time dfs global time seen[j] = 1 seen[j] seen j 1 time += 1 time 1 seentime[j] = time seentime[j] seentime j time stack.append(j) stack.append stack append j while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO  = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time stack s = stack[-1] s stack[-1] stack -1 if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
         not graph[s] graph[s] graph s stack.pop() stack.pop stack pop time += 1 time 1 donetime[s] = time donetime[s] donetime s time continue g_NO  = graph[s].popleft() g_NO graph[s].popleft() [s].popleft [s] graph s popleft if seen[g_NO]:
            continue
         seen[g_NO] seen g_NO continue seen[g_NO] = 1 seen[g_NO] seen g_NO 1 stack.append(g_NO) stack.append stack append g_NO time += 1 time 1 seentime[g_NO] = time seentime[g_NO] seentime g_NO time j j for j in range(1, n+1):
    if seen[j]:
        continue
    dfs(j) j range(1, n+1) range 1 n+1 n 1 if seen[j]:
        continue
     seen[j] seen j continue dfs(j) dfs j for k, a, b in zip(range(1, n+1), seentime[1:], donetime[1:]):
    print(k, a, b) k a b zip(range(1, n+1), seentime[1:], donetime[1:]) zip range(1, n+1) range 1 n+1 n 1 seentime[1:] seentime 1: 1 donetime[1:] donetime 1: 1 print(k, a, b) print k a b seentime = [0]*(n+1) [0]*(n+1) seentime input = sys.stdin.readline sys.stdin.readline input u, k, *v = [int(x) for x in input().split()] [int(x) for x in input().split()] u seen = [0]*(n+1) [0]*(n+1) seen time = 0 0 time donetime = [0]*(n+1) [0]*(n+1) donetime n = int(input()) int(input()) n stack = [] [] stack graph = {i: deque() for i in range(1, n+1)} {i: deque() for i in range(1, n+1)} graph k, *v = [int(x) for x in input().split()] [int(x) for x in input().split()] k def dfs(j):
    global time
    seen[j] = 1
    time += 1
    seentime[j] = time
    stack.append(j)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO  = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time def dfs(j):
    global time
    seen[j] = 1
    time += 1
    seentime[j] = time
    stack.append(j)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO  = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time dfs
import sys
input = sys.stdin.readline
from collections import deque

n = int(input())
graph = {i: deque() for i in range(1, 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)
        #graph[i].append(u)

seen = [0]*(n+1)
stack = []
time = 0
seentime = [0]*(n+1)
donetime = [0]*(n+1)

def dfs(j):
    global time
    seen[j] = 1
    time += 1
    seentime[j] = time
    stack.append(j)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO  = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time

for j in range(1, n+1):
    if seen[j]:
        continue
    dfs(j)

for k, a, b in zip(range(1, n+1), seentime[1:], donetime[1:]):
    print(k, a, b)
