from collections import deque
n = int(input())
v = {i:[] for i in range(n)}
for i in range(n):
    u = list(map(int, input().split()))
    for j in range(2, 2+u[1]):
        v[u[0]-1].append(u[j]-1)

global cnt1 
cnt1 = 0
visited = [False for _ in range(n)]
f = [0 for _ in range(n)]
l = [0 for _ in range(n)]
def DFS(now, visited):
    global cnt1
    cnt1 += 1
    f[now] = cnt1
    visited[now] = True
    for nv in v[now]:
        if visited[nv]:
            continue
        DFS(nv, visited)
    cnt1 += 1
    l[now] = cnt1

for value in range(n):
    if not visited[value]:
        DFS(value, visited)
    
for i in range(n):
    print(i+1, f[i], l[i]) from collections import deque n = int(input()) n int(input()) int input() input i:[] for i in range(n) for i in range(n) i range(n) range n for i in range(n) i [] v = {i:[] for i in range(n)} v {i:[] for i in range(n)} for i in range(n):
    u = list(map(int, input().split()))
    for j in range(2, 2+u[1]):
        v[u[0]-1].append(u[j]-1) i range(n) range n u = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for j in range(2, 2+u[1]):
        v[u[0]-1].append(u[j]-1) j range(2, 2+u[1]) range 2 2+u[1] 2 u[1] u 1 v[u[0]-1].append(u[j]-1) [u[0]-1].append [u[0]-1] v u[0]-1 u[0] u 0 1 append u[j]-1 u[j] u j 1 global cnt1 cnt1 = 0 cnt1 0 False for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) False visited = [False for _ in range(n)] visited [False for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 f = [0 for _ in range(n)] f [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 l = [0 for _ in range(n)] l [0 for _ in range(n)] def DFS(now, visited):
    global cnt1
    cnt1 += 1
    f[now] = cnt1
    visited[now] = True
    for nv in v[now]:
        if visited[nv]:
            continue
        DFS(nv, visited)
    cnt1 += 1
    l[now] = cnt1 DFS global cnt1 cnt1 += 1 cnt1 1 f[now] = cnt1 f[now] f now cnt1 visited[now] = True visited[now] visited now True for nv in v[now]:
        if visited[nv]:
            continue
        DFS(nv, visited)
     nv v[now] v now if visited[nv]:
            continue
         visited[nv] visited nv continue DFS(nv, visited) DFS nv visited cnt1 += 1 cnt1 1 l[now] = cnt1 l[now] l now cnt1 now now visited visited for value in range(n):
    if not visited[value]:
        DFS(value, visited)
     value range(n) range n if not visited[value]:
        DFS(value, visited)
     not visited[value] visited[value] visited value DFS(value, visited) DFS value visited for i in range(n):
    print(i+1, f[i], l[i]) i range(n) range n print(i+1, f[i], l[i]) print i+1 i 1 f[i] f i l[i] l i l = [0 for _ in range(n)] [0 for _ in range(n)] l f = [0 for _ in range(n)] [0 for _ in range(n)] f n = int(input()) int(input()) n v = {i:[] for i in range(n)} {i:[] for i in range(n)} v def DFS(now, visited):
    global cnt1
    cnt1 += 1
    f[now] = cnt1
    visited[now] = True
    for nv in v[now]:
        if visited[nv]:
            continue
        DFS(nv, visited)
    cnt1 += 1
    l[now] = cnt1 def DFS(now, visited):
    global cnt1
    cnt1 += 1
    f[now] = cnt1
    visited[now] = True
    for nv in v[now]:
        if visited[nv]:
            continue
        DFS(nv, visited)
    cnt1 += 1
    l[now] = cnt1 DFS visited = [False for _ in range(n)] [False for _ in range(n)] visited u = list(map(int, input().split())) list(map(int, input().split())) u global cnt1 cnt1 = 0 0 cnt1
from collections import deque
n = int(input())
v = {i:[] for i in range(n)}
for i in range(n):
    u = list(map(int, input().split()))
    for j in range(2, 2+u[1]):
        v[u[0]-1].append(u[j]-1)

global cnt1 
cnt1 = 0
visited = [False for _ in range(n)]
f = [0 for _ in range(n)]
l = [0 for _ in range(n)]
def DFS(now, visited):
    global cnt1
    cnt1 += 1
    f[now] = cnt1
    visited[now] = True
    for nv in v[now]:
        if visited[nv]:
            continue
        DFS(nv, visited)
    cnt1 += 1
    l[now] = cnt1

for value in range(n):
    if not visited[value]:
        DFS(value, visited)
    
for i in range(n):
    print(i+1, f[i], l[i])
