import sys

n = int(input())
G = [None]*(n+1)
for i in range(n):
    u, k, *vs = map(int, input().split())
    G[u] = vs

d = [-1]*(n+1)
f = [-1]*(n+1)
lb = iter(range(1, 2*n+1)).__next__
def dfs(v):
    d[v] = lb()
    for w in G[v]:
        if d[w] != -1: #already visited
            continue
        dfs(w)
    f[v] = lb()

for v in range(1, n+1):
    if d[v] != -1:
        continue
    dfs(v)

for v in range(1, n+1):
    print(f"{v} {d[v]} {f[v]}") import sys sys n = int(input()) n int(input()) int input() input G = [None]*(n+1) G [None]*(n+1) [None] None n+1 n 1 for i in range(n):
    u, k, *vs = map(int, input().split())
    G[u] = vs i range(n) range n u, k, *vs = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *vs vs G[u] = vs G[u] G u vs d = [-1]*(n+1) d [-1]*(n+1) [-1] -1 n+1 n 1 f = [-1]*(n+1) f [-1]*(n+1) [-1] -1 n+1 n 1 lb = iter(range(1, 2*n+1)).__next__ lb iter(range(1, 2*n+1)).__next__ (range(1, 2*n+1)) iter range(1, 2*n+1) range 1 2*n+1 2*n 2 n 1 __next__ def dfs(v):
    d[v] = lb()
    for w in G[v]:
        if d[w] != -1: #already visited
            continue
        dfs(w)
    f[v] = lb() dfs d[v] = lb() d[v] d v lb() lb for w in G[v]:
        if d[w] != -1: #already visited
            continue
        dfs(w)
     w G[v] G v if d[w] != -1: #already visited
            continue
         d[w] != -1 d[w] d w -1 continue dfs(w) dfs w f[v] = lb() f[v] f v lb() lb v v for v in range(1, n+1):
    if d[v] != -1:
        continue
    dfs(v) v range(1, n+1) range 1 n+1 n 1 if d[v] != -1:
        continue
     d[v] != -1 d[v] d v -1 continue dfs(v) dfs v for v in range(1, n+1):
    print(f"{v} {d[v]} {f[v]}") v range(1, n+1) range 1 n+1 n 1 print(f"{v} {d[v]} {f[v]}") print f"{v} {d[v]} {f[v]}" u, k, *vs = map(int, input().split()) map(int, input().split()) u def dfs(v):
    d[v] = lb()
    for w in G[v]:
        if d[w] != -1: #already visited
            continue
        dfs(w)
    f[v] = lb() def dfs(v):
    d[v] = lb()
    for w in G[v]:
        if d[w] != -1: #already visited
            continue
        dfs(w)
    f[v] = lb() dfs lb = iter(range(1, 2*n+1)).__next__ iter(range(1, 2*n+1)).__next__ lb n = int(input()) int(input()) n d = [-1]*(n+1) [-1]*(n+1) d f = [-1]*(n+1) [-1]*(n+1) f G = [None]*(n+1) [None]*(n+1) G k, *vs = map(int, input().split()) map(int, input().split()) k
import sys

n = int(input())
G = [None]*(n+1)
for i in range(n):
    u, k, *vs = map(int, input().split())
    G[u] = vs

d = [-1]*(n+1)
f = [-1]*(n+1)
lb = iter(range(1, 2*n+1)).__next__
def dfs(v):
    d[v] = lb()
    for w in G[v]:
        if d[w] != -1: #already visited
            continue
        dfs(w)
    f[v] = lb()

for v in range(1, n+1):
    if d[v] != -1:
        continue
    dfs(v)

for v in range(1, n+1):
    print(f"{v} {d[v]} {f[v]}")
