n = int(input())
g = []
for i in range(n):
    a = list(map(int,input().split()))
    g.append(a[2:])
d = [0]*n
f = [0]*n
global t
t = 0

def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t

for i in range(n):
    if d[i] == 0:
        t += 1
        d[i] = t
        find(i+1)
for i in range(n):
    print(i+1, d[i], f[i])
 n = int(input()) n int(input()) int input() input g = [] g [] for i in range(n):
    a = list(map(int,input().split()))
    g.append(a[2:]) 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 g.append(a[2:]) g.append g append a[2:] a 2: 2 d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n global t t = 0 t 0 def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t find global t if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t len(g[x-1]) == 0 len(g[x-1]) len g[x-1] g x-1 x 1 0 t += 1 t 1 f[x-1] = t f[x-1] f x-1 x 1 t for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
         i g[x-1] g x-1 x 1 if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
         d[i-1] == 0 d[i-1] d i-1 i 1 0 t += 1 t 1 d[i-1] = t d[i-1] d i-1 i 1 t find(i) find i t += 1 t 1 f[x-1] = t f[x-1] f x-1 x 1 t x x for i in range(n):
    if d[i] == 0:
        t += 1
        d[i] = t
        find(i+1) i range(n) range n if d[i] == 0:
        t += 1
        d[i] = t
        find(i+1) d[i] == 0 d[i] d i 0 t += 1 t 1 d[i] = t d[i] d i t find(i+1) find i+1 i 1 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 def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t find f = [0]*n [0]*n f n = int(input()) int(input()) n t += 1 1 t global t t = 0 0 t g = [] [] g a = list(map(int,input().split())) list(map(int,input().split())) a d = [0]*n [0]*n d
n = int(input())
g = []
for i in range(n):
    a = list(map(int,input().split()))
    g.append(a[2:])
d = [0]*n
f = [0]*n
global t
t = 0

def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t

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

