n = int(input())
d = [0]*(n+1)
f = [0]*(n+1)
t = 1

adjacent_list = [[] for _ in range(n+1)]
for i in range(n):
    e = list(map(int,input().split()))
    if e[1] != 0:
        adjacent_list[i+1].extend(e[2:])
#print(adjacent_list)

def dfs(v):
    if d[v] >= 1:
        return

    global t
    if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
    t += 1

    for nv in adjacent_list[v]:
        dfs(nv)
    f[v] = t
    t += 1

for v in range(1,n+1):
    dfs(v)

#dfs(1)
#print(d)
#print(f)
for i in range(1,n+1):
    print(i, d[i], f[i]) n = int(input()) n int(input()) int input() input d = [0]*(n+1) d [0]*(n+1) [0] 0 n+1 n 1 f = [0]*(n+1) f [0]*(n+1) [0] 0 n+1 n 1 t = 1 t 1 [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] adjacent_list = [[] for _ in range(n+1)] adjacent_list [[] for _ in range(n+1)] for i in range(n):
    e = list(map(int,input().split()))
    if e[1] != 0:
        adjacent_list[i+1].extend(e[2:])
#print(adjacent_list) i range(n) range n e = list(map(int,input().split())) e list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split if e[1] != 0:
        adjacent_list[i+1].extend(e[2:])
#print(adjacent_list) e[1] != 0 e[1] e 1 0 adjacent_list[i+1].extend(e[2:]) [i+1].extend [i+1] adjacent_list i+1 i 1 extend e[2:] e 2: 2 def dfs(v):
    if d[v] >= 1:
        return

    global t
    if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
    t += 1

    for nv in adjacent_list[v]:
        dfs(nv)
    f[v] = t
    t += 1 dfs if d[v] >= 1:
        return

     d[v] >= 1 d[v] d v 1 return global t if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
     d[v] == 0 d[v] d v 0 d[v] = t d[v] d v t t += 1 t 1 for nv in adjacent_list[v]:
        dfs(nv)
     nv adjacent_list[v] adjacent_list v dfs(nv) dfs nv f[v] = t f[v] f v t t += 1 t 1 v v for v in range(1,n+1):
    dfs(v)

#dfs(1)
#print(d)
#print(f) v range(1,n+1) range 1 n+1 n 1 dfs(v) dfs v for i in range(1,n+1):
    print(i, d[i], f[i]) i range(1,n+1) range 1 n+1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i d = [0]*(n+1) [0]*(n+1) d t = 1 1 t f = [0]*(n+1) [0]*(n+1) f e = list(map(int,input().split())) list(map(int,input().split())) e n = int(input()) int(input()) n def dfs(v):
    if d[v] >= 1:
        return

    global t
    if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
    t += 1

    for nv in adjacent_list[v]:
        dfs(nv)
    f[v] = t
    t += 1 def dfs(v):
    if d[v] >= 1:
        return

    global t
    if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
    t += 1

    for nv in adjacent_list[v]:
        dfs(nv)
    f[v] = t
    t += 1 dfs adjacent_list = [[] for _ in range(n+1)] [[] for _ in range(n+1)] adjacent_list
n = int(input())
d = [0]*(n+1)
f = [0]*(n+1)
t = 1

adjacent_list = [[] for _ in range(n+1)]
for i in range(n):
    e = list(map(int,input().split()))
    if e[1] != 0:
        adjacent_list[i+1].extend(e[2:])
#print(adjacent_list)

def dfs(v):
    if d[v] >= 1:
        return

    global t
    if d[v] == 0: #未発見なら発見時刻を記入
        d[v] = t
    t += 1

    for nv in adjacent_list[v]:
        dfs(nv)
    f[v] = t
    t += 1

for v in range(1,n+1):
    dfs(v)

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