# coding: utf-8
def depth(i, adj, Dep, Arr, times):
    if Dep[i-1]:
        return times
    Dep[i-1]=times
    times+=1
    # t=[depth(j, adj, Dep, f, times) j in adj[i-1]]
    for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
    Arr[i - 1]=times
    times+=1
    return times


n=int(input())
adj=[list(map(int, input().split()))[2:] for i in range(n)]

d,f=[0]*n,[0]*n

t=1

dlist=[i for i in range(n) if d[i]==0]

for i in dlist:
    t = depth(i + 1, adj, d, f, t)

for i, df in enumerate(zip(d, f)):
    print(i + 1, *df) def depth(i, adj, Dep, Arr, times):
    if Dep[i-1]:
        return times
    Dep[i-1]=times
    times+=1
    # t=[depth(j, adj, Dep, f, times) j in adj[i-1]]
    for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
    Arr[i - 1]=times
    times+=1
    return times depth if Dep[i-1]:
        return times
     Dep[i-1] Dep i-1 i 1 return times times Dep[i-1]=times Dep[i-1] Dep i-1 i 1 times times+=1 times 1 for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
     j adj[i-1] adj i-1 i 1 times=depth(j, adj, Dep, Arr, times) times depth(j, adj, Dep, Arr, times) depth j adj Dep Arr times Arr[i - 1]=times Arr[i - 1] Arr i - 1 i 1 times times+=1 times 1 return times times i i adj adj Dep Dep Arr Arr times times n=int(input()) n int(input()) int input() input list(map(int, input().split()))[2:] for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(map(int, input().split()))[2:] (map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 2: 2 adj=[list(map(int, input().split()))[2:] for i in range(n)] adj [list(map(int, input().split()))[2:] for i in range(n)] d,f=[0]*n,[0]*n d [0]*n [0] 0 n f [0]*n [0] 0 n t=1 t 1 i for i in range(n) if d[i]==0 for i in range(n) if d[i]==0 i range(n) range n d[i]==0 d[i] d i 0 if d[i]==0 i dlist=[i for i in range(n) if d[i]==0] dlist [i for i in range(n) if d[i]==0] for i in dlist:
    t = depth(i + 1, adj, d, f, t) i dlist t = depth(i + 1, adj, d, f, t) t depth(i + 1, adj, d, f, t) depth i + 1 i 1 adj d f t for i, df in enumerate(zip(d, f)):
    print(i + 1, *df) i df enumerate(zip(d, f)) enumerate zip(d, f) zip d f print(i + 1, *df) print i + 1 i 1 *df df def depth(i, adj, Dep, Arr, times):
    if Dep[i-1]:
        return times
    Dep[i-1]=times
    times+=1
    # t=[depth(j, adj, Dep, f, times) j in adj[i-1]]
    for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
    Arr[i - 1]=times
    times+=1
    return times def depth(i, adj, Dep, Arr, times):
    if Dep[i-1]:
        return times
    Dep[i-1]=times
    times+=1
    # t=[depth(j, adj, Dep, f, times) j in adj[i-1]]
    for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
    Arr[i - 1]=times
    times+=1
    return times depth t = depth(i + 1, adj, d, f, t) depth(i + 1, adj, d, f, t) t d,f=[0]*n,[0]*n [0]*n d t=1 1 t n=int(input()) int(input()) n f=[0]*n,[0]*n [0]*n f dlist=[i for i in range(n) if d[i]==0] [i for i in range(n) if d[i]==0] dlist adj=[list(map(int, input().split()))[2:] for i in range(n)] [list(map(int, input().split()))[2:] for i in range(n)] adj
# coding: utf-8
def depth(i, adj, Dep, Arr, times):
    if Dep[i-1]:
        return times
    Dep[i-1]=times
    times+=1
    # t=[depth(j, adj, Dep, f, times) j in adj[i-1]]
    for j in adj[i-1]:
        times=depth(j, adj, Dep, Arr, times)
    Arr[i - 1]=times
    times+=1
    return times


n=int(input())
adj=[list(map(int, input().split()))[2:] for i in range(n)]

d,f=[0]*n,[0]*n

t=1

dlist=[i for i in range(n) if d[i]==0]

for i in dlist:
    t = depth(i + 1, adj, d, f, t)

for i, df in enumerate(zip(d, f)):
    print(i + 1, *df)