from collections import deque
n = int(input())
data = [None]*n
unvisited = [1]*n
for _ in range(n):
    a,*b = map(int,input().split())
    a -= 1
    data[a] = deque([i-1 for i in b[1:]])

d = [-1]*n
f = [-1]*n
t = 0

dq = deque([])
for u in range(n):
    if unvisited[u]:
        dq.append(u)
        unvisited[u] = 0
        t += 1
        d[u] = t
        while dq:
            k = dq[-1]
            if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t

for i in range(n):
    print(i+1,d[i],f[i]) from collections import deque n = int(input()) n int(input()) int input() input data = [None]*n data [None]*n [None] None n unvisited = [1]*n unvisited [1]*n [1] 1 n for _ in range(n):
    a,*b = map(int,input().split())
    a -= 1
    data[a] = deque([i-1 for i in b[1:]]) _ range(n) range n a,*b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split *b b a -= 1 a 1 i-1 for i in b[1:] for i in b[1:] i b[1:] b 1: 1 for i in b[1:] i-1 i 1 data[a] = deque([i-1 for i in b[1:]]) data[a] data a deque([i-1 for i in b[1:]]) deque [i-1 for i in b[1:]] d = [-1]*n d [-1]*n [-1] -1 n f = [-1]*n f [-1]*n [-1] -1 n t = 0 t 0 dq = deque([]) dq deque([]) deque [] for u in range(n):
    if unvisited[u]:
        dq.append(u)
        unvisited[u] = 0
        t += 1
        d[u] = t
        while dq:
            k = dq[-1]
            if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t u range(n) range n if unvisited[u]:
        dq.append(u)
        unvisited[u] = 0
        t += 1
        d[u] = t
        while dq:
            k = dq[-1]
            if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t unvisited[u] unvisited u dq.append(u) dq.append dq append u unvisited[u] = 0 unvisited[u] unvisited u 0 t += 1 t 1 d[u] = t d[u] d u t while dq:
            k = dq[-1]
            if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t dq k = dq[-1] k dq[-1] dq -1 if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t data[k] data k v = data[k].popleft() v data[k].popleft() [k].popleft [k] data k popleft if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
             unvisited[v] unvisited v unvisited[v] = 0 unvisited[v] unvisited v 0 t += 1 t 1 d[v] = t d[v] d v t dq.append(v) dq.append dq append v dq.pop() dq.pop dq pop t += 1 t 1 f[k] = t f[k] f k t 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 unvisited = [1]*n [1]*n unvisited d = [-1]*n [-1]*n d t += 1 1 t dq = deque([]) deque([]) dq t += 1 1 t t += 1 1 t n = int(input()) int(input()) n v = data[k].popleft() data[k].popleft() v data = [None]*n [None]*n data k = dq[-1] dq[-1] k f = [-1]*n [-1]*n f a,*b = map(int,input().split()) map(int,input().split()) a a -= 1 1 a t = 0 0 t
from collections import deque
n = int(input())
data = [None]*n
unvisited = [1]*n
for _ in range(n):
    a,*b = map(int,input().split())
    a -= 1
    data[a] = deque([i-1 for i in b[1:]])

d = [-1]*n
f = [-1]*n
t = 0

dq = deque([])
for u in range(n):
    if unvisited[u]:
        dq.append(u)
        unvisited[u] = 0
        t += 1
        d[u] = t
        while dq:
            k = dq[-1]
            if data[k]:
                v = data[k].popleft()
                if unvisited[v]:
                    unvisited[v] = 0
                    t += 1
                    d[v] = t
                    dq.append(v)
            else:
                dq.pop()
                t += 1
                f[k] = t

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