# input
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v_list = list(map(int, input().split()))
    for v in v_list:
        A[u-1][v-1] = 1

# init
d = [0] * n
f = [0] * n
t = 0

# recursive
def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs
for i in range(n):
    if d[i] == 0:
        dfs(i)

# output
for i in range(n):
    print(i+1, d[i], f[i]) n = int(input()) n int(input()) int input() input [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] A = [[0 for i in range(n)] for j in range(n)] A [[0 for i in range(n)] for j in range(n)] for i in range(n):
    u, k, *v_list = list(map(int, input().split()))
    for v in v_list:
        A[u-1][v-1] = 1

# init i range(n) range n u, k, *v_list = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *v_list v_list for v in v_list:
        A[u-1][v-1] = 1

# init v v_list A[u-1][v-1] = 1 A[u-1][v-1] [u-1] A u-1 u 1 v-1 v 1 1 d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n t = 0 t 0 def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs dfs global t t += 1 t 1 d[u] = t d[u] d u t for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
     v range(n) range n if A[u][v] == 1 and d[v] == 0:
            dfs(v)
     A[u][v] == 1 and d[v] == 0 A[u][v] == 1 A[u][v] [u] A u v 1 d[v] == 0 d[v] d v 0 dfs(v) dfs v t += 1 t 1 f[u] = t f[u] f u t u u for i in range(n):
    if d[i] == 0:
        dfs(i)

# output i range(n) range n if d[i] == 0:
        dfs(i)

# output d[i] == 0 d[i] d i 0 dfs(i) dfs i for i in range(n):
    print(i+1, d[i], f[i]) i range(n) range n print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i d = [0] * n [0] * n d def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs dfs A = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] A u, k, *v_list = list(map(int, input().split())) list(map(int, input().split())) u t = 0 0 t f = [0] * n [0] * n f n = int(input()) int(input()) n k, *v_list = list(map(int, input().split())) list(map(int, input().split())) k
# input
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v_list = list(map(int, input().split()))
    for v in v_list:
        A[u-1][v-1] = 1

# init
d = [0] * n
f = [0] * n
t = 0

# recursive
def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs
for i in range(n):
    if d[i] == 0:
        dfs(i)

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