import sys
sys.setrecursionlimit(10**7) 

def dfs(G,v):
    global ptr
    first_order[v] = ptr
    ptr += 1
    seen[v] = True
    for next in G[v]:
        if seen[next]:
            continue
        dfs(G,next)

    last_order[v] = ptr
    ptr+=1

n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
    a = list(map(int, input().split()))
    u = a[0]
    k = a[1]
    v = a[2:]
    for i in v:
        G[u-1].append(i-1)

seen = [False]*n
first_order = [0]*n
last_order = [0]*n
ptr = 0
for i in range(n):
    if seen[i]:
        continue
    dfs(G,i)

for i in range(n):
    print('{} {} {}'.format(i+1,first_order[i]+1,last_order[i]+1)) import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def dfs(G,v):
    global ptr
    first_order[v] = ptr
    ptr += 1
    seen[v] = True
    for next in G[v]:
        if seen[next]:
            continue
        dfs(G,next)

    last_order[v] = ptr
    ptr+=1 dfs global ptr first_order[v] = ptr first_order[v] first_order v ptr ptr += 1 ptr 1 seen[v] = True seen[v] seen v True for next in G[v]:
        if seen[next]:
            continue
        dfs(G,next)

     next G[v] G v if seen[next]:
            continue
         seen[next] seen next continue dfs(G,next) dfs G next last_order[v] = ptr last_order[v] last_order v ptr ptr+=1 ptr 1 G G v v n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] G = [[] for _ in range(n)] G [[] for _ in range(n)] for _ in range(n):
    a = list(map(int, input().split()))
    u = a[0]
    k = a[1]
    v = a[2:]
    for i in v:
        G[u-1].append(i-1) _ range(n) range n a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = a[0] u a[0] a 0 k = a[1] k a[1] a 1 v = a[2:] v a[2:] a 2: 2 for i in v:
        G[u-1].append(i-1) i v G[u-1].append(i-1) [u-1].append [u-1] G u-1 u 1 append i-1 i 1 seen = [False]*n seen [False]*n [False] False n first_order = [0]*n first_order [0]*n [0] 0 n last_order = [0]*n last_order [0]*n [0] 0 n ptr = 0 ptr 0 for i in range(n):
    if seen[i]:
        continue
    dfs(G,i) i range(n) range n if seen[i]:
        continue
     seen[i] seen i continue dfs(G,i) dfs G i for i in range(n):
    print('{} {} {}'.format(i+1,first_order[i]+1,last_order[i]+1)) i range(n) range n print('{} {} {}'.format(i+1,first_order[i]+1,last_order[i]+1)) print '{} {} {}'.format(i+1,first_order[i]+1,last_order[i]+1) '{} {} {}'.format '{} {} {}' format i+1 i 1 first_order[i]+1 first_order[i] first_order i 1 last_order[i]+1 last_order[i] last_order i 1 v = a[2:] a[2:] v def dfs(G,v):
    global ptr
    first_order[v] = ptr
    ptr += 1
    seen[v] = True
    for next in G[v]:
        if seen[next]:
            continue
        dfs(G,next)

    last_order[v] = ptr
    ptr+=1 def dfs(G,v):
    global ptr
    first_order[v] = ptr
    ptr += 1
    seen[v] = True
    for next in G[v]:
        if seen[next]:
            continue
        dfs(G,next)

    last_order[v] = ptr
    ptr+=1 dfs n = int(input()) int(input()) n seen = [False]*n [False]*n seen last_order = [0]*n [0]*n last_order a = list(map(int, input().split())) list(map(int, input().split())) a u = a[0] a[0] u ptr = 0 0 ptr G = [[] for _ in range(n)] [[] for _ in range(n)] G k = a[1] a[1] k first_order = [0]*n [0]*n first_order
import sys
sys.setrecursionlimit(10**7) 

def dfs(G,v):
    global ptr
    first_order[v] = ptr
    ptr += 1
    seen[v] = True
    for next in G[v]:
        if seen[next]:
            continue
        dfs(G,next)

    last_order[v] = ptr
    ptr+=1

n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
    a = list(map(int, input().split()))
    u = a[0]
    k = a[1]
    v = a[2:]
    for i in v:
        G[u-1].append(i-1)

seen = [False]*n
first_order = [0]*n
last_order = [0]*n
ptr = 0
for i in range(n):
    if seen[i]:
        continue
    dfs(G,i)

for i in range(n):
    print('{} {} {}'.format(i+1,first_order[i]+1,last_order[i]+1))
