# 24
# ALDS_11_B - 深さ優先探索

from collections import deque

n = int(input())
u_l = []
k_l = []
v_l = []
for i in range(n):
    _in = input()
    _v_l = []
    for j,_ in enumerate(_in.split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l)

def dfs(v):
    global count
    c_l[v] = True
    d_l[v] = count
    count += 1
    for i in range(k_l[v]):
        _v = v_l[v][i]-1
        if not c_l[_v]:
            dfs(_v)
    f_l[v] = count
    count += 1

d_l = [None]*n
f_l = [None]*n
c_l = [False]*n
count = 1
while False in c_l:
    dfs(c_l.index(False))

for idx, d, f in zip(list(range(1,n+1)), d_l, f_l):
    print(idx, d, f) from collections import deque n = int(input()) n int(input()) int input() input u_l = [] u_l [] k_l = [] k_l [] v_l = [] v_l [] for i in range(n):
    _in = input()
    _v_l = []
    for j,_ in enumerate(_in.split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l) i range(n) range n _in = input() _in input() input _v_l = [] _v_l [] for j,_ in enumerate(_in.split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
     j _ enumerate(_in.split()) enumerate _in.split() _in.split _in split if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
     j == 0 j 0 u_l.append(int(_)) u_l.append u_l append int(_) int _ elif j == 1:
            k_l.append(int(_))
         j == 1 j 1 k_l.append(int(_)) k_l.append k_l append int(_) int _ _v_l.append(int(_)) _v_l.append _v_l append int(_) int _ v_l.append(_v_l) v_l.append v_l append _v_l def dfs(v):
    global count
    c_l[v] = True
    d_l[v] = count
    count += 1
    for i in range(k_l[v]):
        _v = v_l[v][i]-1
        if not c_l[_v]:
            dfs(_v)
    f_l[v] = count
    count += 1 dfs global count c_l[v] = True c_l[v] c_l v True d_l[v] = count d_l[v] d_l v count count += 1 count 1 for i in range(k_l[v]):
        _v = v_l[v][i]-1
        if not c_l[_v]:
            dfs(_v)
     i range(k_l[v]) range k_l[v] k_l v _v = v_l[v][i]-1 _v v_l[v][i]-1 v_l[v][i] [v] v_l v i 1 if not c_l[_v]:
            dfs(_v)
     not c_l[_v] c_l[_v] c_l _v dfs(_v) dfs _v f_l[v] = count f_l[v] f_l v count count += 1 count 1 v v d_l = [None]*n d_l [None]*n [None] None n f_l = [None]*n f_l [None]*n [None] None n c_l = [False]*n c_l [False]*n [False] False n count = 1 count 1 while False in c_l:
    dfs(c_l.index(False)) False in c_l False c_l dfs(c_l.index(False)) dfs c_l.index(False) c_l.index c_l index False for idx, d, f in zip(list(range(1,n+1)), d_l, f_l):
    print(idx, d, f) idx d f zip(list(range(1,n+1)), d_l, f_l) zip list(range(1,n+1)) list range(1,n+1) range 1 n+1 n 1 d_l f_l print(idx, d, f) print idx d f _v_l = [] [] _v_l d_l = [None]*n [None]*n d_l _in = input() input() _in n = int(input()) int(input()) n c_l = [False]*n [False]*n c_l v_l = [] [] v_l u_l = [] [] u_l k_l = [] [] k_l def dfs(v):
    global count
    c_l[v] = True
    d_l[v] = count
    count += 1
    for i in range(k_l[v]):
        _v = v_l[v][i]-1
        if not c_l[_v]:
            dfs(_v)
    f_l[v] = count
    count += 1 def dfs(v):
    global count
    c_l[v] = True
    d_l[v] = count
    count += 1
    for i in range(k_l[v]):
        _v = v_l[v][i]-1
        if not c_l[_v]:
            dfs(_v)
    f_l[v] = count
    count += 1 dfs f_l = [None]*n [None]*n f_l count = 1 1 count
# 24
# ALDS_11_B - 深さ優先探索

from collections import deque

n = int(input())
u_l = []
k_l = []
v_l = []
for i in range(n):
    _in = input()
    _v_l = []
    for j,_ in enumerate(_in.split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l)

def dfs(v):
    global count
    c_l[v] = True
    d_l[v] = count
    count += 1
    for i in range(k_l[v]):
        _v = v_l[v][i]-1
        if not c_l[_v]:
            dfs(_v)
    f_l[v] = count
    count += 1

d_l = [None]*n
f_l = [None]*n
c_l = [False]*n
count = 1
while False in c_l:
    dfs(c_l.index(False))

for idx, d, f in zip(list(range(1,n+1)), d_l, f_l):
    print(idx, d, f)
