N = int(input())

E = [None] * (N+1)
for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs

d = [0] * (N+1)
f = [0] * (N+1)
t = 0

def dfs(v):
    global t, d, f
    if d[v]:
        return
    t += 1
    d[v] = t
    for u in E[v]:
        dfs(u)
    t += 1
    f[v] = t

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

for v in range(1, N+1):
    print(v, d[v], f[v])
 N = int(input()) N int(input()) int input() input E = [None] * (N+1) E [None] * (N+1) [None] None N+1 N 1 for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs _ range(N) range N u, k, *vs = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *vs vs E[u] = vs E[u] E u vs 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 = 0 t 0 def dfs(v):
    global t, d, f
    if d[v]:
        return
    t += 1
    d[v] = t
    for u in E[v]:
        dfs(u)
    t += 1
    f[v] = t dfs global t, d, f if d[v]:
        return
     d[v] d v return t += 1 t 1 d[v] = t d[v] d v t for u in E[v]:
        dfs(u)
     u E[v] E v dfs(u) dfs u t += 1 t 1 f[v] = t f[v] f v t v v for v in range(1, N+1):
    dfs(v) v range(1, N+1) range 1 N+1 N 1 dfs(v) dfs v for v in range(1, N+1):
    print(v, d[v], f[v]) v range(1, N+1) range 1 N+1 N 1 print(v, d[v], f[v]) print v d[v] d v f[v] f v N = int(input()) int(input()) N E = [None] * (N+1) [None] * (N+1) E k, *vs = list(map(int, input().split())) list(map(int, input().split())) k u, k, *vs = list(map(int, input().split())) list(map(int, input().split())) u def dfs(v):
    global t, d, f
    if d[v]:
        return
    t += 1
    d[v] = t
    for u in E[v]:
        dfs(u)
    t += 1
    f[v] = t def dfs(v):
    global t, d, f
    if d[v]:
        return
    t += 1
    d[v] = t
    for u in E[v]:
        dfs(u)
    t += 1
    f[v] = t dfs d = [0] * (N+1) [0] * (N+1) d f = [0] * (N+1) [0] * (N+1) f t = 0 0 t
N = int(input())

E = [None] * (N+1)
for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs

d = [0] * (N+1)
f = [0] * (N+1)
t = 0

def dfs(v):
    global t, d, f
    if d[v]:
        return
    t += 1
    d[v] = t
    for u in E[v]:
        dfs(u)
    t += 1
    f[v] = t

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

for v in range(1, N+1):
    print(v, d[v], f[v])

