n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
g = [0] * n

time = 0

for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

def search(i):
    global time
    time = time + 1
    d[i] = time
    g[i] = 1
    for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
    time = time + 1
    f[i] = time

for i in range(n):
    if g[i] == 0:
        search(i)
[print(i+1, d[i], f[i]) for i in range(n)] 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)] graph = [[0 for i in range(n)] for j in range(n)] graph [[0 for i in range(n)] for j in range(n)] d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n g = [0] * n g [0] * n [0] 0 n time = 0 time 0 for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1 i range(n) range n a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1 j range(0, a[1], 1) range 0 a[1] a 1 1 graph[a[0] - 1][a[2 + j] - 1] = 1 graph[a[0] - 1][a[2 + j] - 1] [a[0] - 1] graph a[0] - 1 a[0] a 0 1 a[2 + j] - 1 a[2 + j] a 2 + j 2 j 1 1 def search(i):
    global time
    time = time + 1
    d[i] = time
    g[i] = 1
    for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
    time = time + 1
    f[i] = time search global time time = time + 1 time time + 1 time 1 d[i] = time d[i] d i time g[i] = 1 g[i] g i 1 for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
     j range(n) range n if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
     (graph[i][j] == 1) & (g[j] == 0) graph[i][j] == 1 graph[i][j] [i] graph i j 1 g[j] == 0 g[j] g j 0 search(j) search j time = time + 1 time time + 1 time 1 f[i] = time f[i] f i time i i for i in range(n):
    if g[i] == 0:
        search(i) i range(n) range n if g[i] == 0:
        search(i) g[i] == 0 g[i] g i 0 search(i) search i print(i+1, d[i], f[i]) for i in range(n) for i in range(n) i range(n) range n for i in range(n) print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i [print(i+1, d[i], f[i]) for i in range(n)] f = [0] * n [0] * n f d = [0] * n [0] * n d a = list(map(int, input().split())) list(map(int, input().split())) a n = int(input()) int(input()) n time = 0 0 time graph = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] graph def search(i):
    global time
    time = time + 1
    d[i] = time
    g[i] = 1
    for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
    time = time + 1
    f[i] = time def search(i):
    global time
    time = time + 1
    d[i] = time
    g[i] = 1
    for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
    time = time + 1
    f[i] = time search g = [0] * n [0] * n g
n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
g = [0] * n

time = 0

for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

def search(i):
    global time
    time = time + 1
    d[i] = time
    g[i] = 1
    for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
    time = time + 1
    f[i] = time

for i in range(n):
    if g[i] == 0:
        search(i)
[print(i+1, d[i], f[i]) for i in range(n)]
