#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n = int(input())
G1 = [0]*n
G2 = [[0]*n for i in range(n)]
d = [0]*n
f = [0]*n
for i in range(n):
    inp = tuple(map(int, input().split()))
    G1[inp[0]-1]=sorted(inp[2:])
time=0

def dfs(vertex):
    if d[vertex]:return
    global time
    time+=1
    d[vertex]=time
    for v in G1[vertex]:
        if not d[v-1]:
            dfs(v-1)
    time+=1
    f[vertex]=time
    return

for i in range(n):
    dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])
    
    
 import sys sys input = lambda: sys.stdin.readline()[:-1] input lambda: sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 n = int(input()) n int(input()) int input() input G1 = [0]*n G1 [0]*n [0] 0 n [0]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*n [0] 0 n G2 = [[0]*n for i in range(n)] G2 [[0]*n for i in range(n)] d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n for i in range(n):
    inp = tuple(map(int, input().split()))
    G1[inp[0]-1]=sorted(inp[2:]) i range(n) range n inp = tuple(map(int, input().split())) inp tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split G1[inp[0]-1]=sorted(inp[2:]) G1[inp[0]-1] G1 inp[0]-1 inp[0] inp 0 1 sorted(inp[2:]) sorted inp[2:] inp 2: 2 time=0 time 0 def dfs(vertex):
    if d[vertex]:return
    global time
    time+=1
    d[vertex]=time
    for v in G1[vertex]:
        if not d[v-1]:
            dfs(v-1)
    time+=1
    f[vertex]=time
    return dfs if d[vertex]:return
     d[vertex] d vertex global time time+=1 time 1 d[vertex]=time d[vertex] d vertex time for v in G1[vertex]:
        if not d[v-1]:
            dfs(v-1)
     v G1[vertex] G1 vertex if not d[v-1]:
            dfs(v-1)
     not d[v-1] d[v-1] d v-1 v 1 dfs(v-1) dfs v-1 v 1 time+=1 time 1 f[vertex]=time f[vertex] f vertex time return vertex vertex for i in range(n):
    dfs(i) i range(n) range n dfs(i) dfs i for i in range(n):
    print(i+1,d[i],f[i])
    
     i range(n) range n print(i+1,d[i],f[i]) print i+1 i 1 d[i] d i f[i] f i G2 = [[0]*n for i in range(n)] [[0]*n for i in range(n)] G2 d = [0]*n [0]*n d input = lambda: sys.stdin.readline()[:-1] lambda: sys.stdin.readline()[:-1] input f = [0]*n [0]*n f G1 = [0]*n [0]*n G1 time=0 0 time def dfs(vertex):
    if d[vertex]:return
    global time
    time+=1
    d[vertex]=time
    for v in G1[vertex]:
        if not d[v-1]:
            dfs(v-1)
    time+=1
    f[vertex]=time
    return def dfs(vertex):
    if d[vertex]:return
    global time
    time+=1
    d[vertex]=time
    for v in G1[vertex]:
        if not d[v-1]:
            dfs(v-1)
    time+=1
    f[vertex]=time
    return dfs n = int(input()) int(input()) n inp = tuple(map(int, input().split())) tuple(map(int, input().split())) inp
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n = int(input())
G1 = [0]*n
G2 = [[0]*n for i in range(n)]
d = [0]*n
f = [0]*n
for i in range(n):
    inp = tuple(map(int, input().split()))
    G1[inp[0]-1]=sorted(inp[2:])
time=0

def dfs(vertex):
    if d[vertex]:return
    global time
    time+=1
    d[vertex]=time
    for v in G1[vertex]:
        if not d[v-1]:
            dfs(v-1)
    time+=1
    f[vertex]=time
    return

for i in range(n):
    dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])
    
    

