def depth_search(i, adj, d, f, t):
    if d[i - 1]:
        return t
    d[i - 1] = t
    t += 1
    for v in adj[i - 1]:
        t = depth_search(v, adj, d, f, t)
    f[i - 1] = t
    t += 1
    return t
n = int(input())
adj = [list(map(int, input().split()))[2:] for _ in range(n)]

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

t = 1
for i in range(n):
    if d[i] == 0:
        t = depth_search(i + 1, adj, d, f, t)

for i, df in enumerate(zip(d, f)):
    print(i + 1, *df)    def depth_search(i, adj, d, f, t):
    if d[i - 1]:
        return t
    d[i - 1] = t
    t += 1
    for v in adj[i - 1]:
        t = depth_search(v, adj, d, f, t)
    f[i - 1] = t
    t += 1
    return t depth_search if d[i - 1]:
        return t
     d[i - 1] d i - 1 i 1 return t t d[i - 1] = t d[i - 1] d i - 1 i 1 t t += 1 t 1 for v in adj[i - 1]:
        t = depth_search(v, adj, d, f, t)
     v adj[i - 1] adj i - 1 i 1 t = depth_search(v, adj, d, f, t) t depth_search(v, adj, d, f, t) depth_search v adj d f t f[i - 1] = t f[i - 1] f i - 1 i 1 t t += 1 t 1 return t t i i adj adj d d f f t t n = int(input()) n int(input()) int input() input list(map(int, input().split()))[2:] for _ in range(n) for _ in range(n) _ range(n) range n for _ 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 _ in range(n)] adj [list(map(int, input().split()))[2:] for _ in range(n)] d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n t = 1 t 1 for i in range(n):
    if d[i] == 0:
        t = depth_search(i + 1, adj, d, f, t) i range(n) range n if d[i] == 0:
        t = depth_search(i + 1, adj, d, f, t) d[i] == 0 d[i] d i 0 t = depth_search(i + 1, adj, d, f, t) t depth_search(i + 1, adj, d, f, t) depth_search 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 adj = [list(map(int, input().split()))[2:] for _ in range(n)] [list(map(int, input().split()))[2:] for _ in range(n)] adj def depth_search(i, adj, d, f, t):
    if d[i - 1]:
        return t
    d[i - 1] = t
    t += 1
    for v in adj[i - 1]:
        t = depth_search(v, adj, d, f, t)
    f[i - 1] = t
    t += 1
    return t def depth_search(i, adj, d, f, t):
    if d[i - 1]:
        return t
    d[i - 1] = t
    t += 1
    for v in adj[i - 1]:
        t = depth_search(v, adj, d, f, t)
    f[i - 1] = t
    t += 1
    return t depth_search t = 1 1 t n = int(input()) int(input()) n d = [0] * n [0] * n d f = [0] * n [0] * n f t = depth_search(i + 1, adj, d, f, t) depth_search(i + 1, adj, d, f, t) t
def depth_search(i, adj, d, f, t):
    if d[i - 1]:
        return t
    d[i - 1] = t
    t += 1
    for v in adj[i - 1]:
        t = depth_search(v, adj, d, f, t)
    f[i - 1] = t
    t += 1
    return t
n = int(input())
adj = [list(map(int, input().split()))[2:] for _ in range(n)]

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

t = 1
for i in range(n):
    if d[i] == 0:
        t = depth_search(i + 1, adj, d, f, t)

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