def DFS(s, t):
    t += 1
    flag[s] = 1
    d[s] = t
    for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
    f[s] = t + 1

n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [0 for i in range(n+1)]
f = [0 for i in range(n+1)]

for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1

flag = [0 for i in range(n+1)]
for i in range(1, n+1):
    if flag[i] == 0:
        DFS(i, max(f))

for i in range(1, n+1):
    print(str(i) + " " + str(d[i]) + " " + str(f[i])) def DFS(s, t):
    t += 1
    flag[s] = 1
    d[s] = t
    for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
    f[s] = t + 1 DFS t += 1 t 1 flag[s] = 1 flag[s] flag s 1 d[s] = t d[s] d s t for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
     i range(1, n+1) range 1 n+1 n 1 if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
     G[s][i] == 1 G[s][i] [s] G s i 1 if flag[i] == 0:
                DFS(i, t)
                t = f[i]
     flag[i] == 0 flag[i] flag i 0 DFS(i, t) DFS i t t = f[i] t f[i] f i f[s] = t + 1 f[s] f s t + 1 t 1 s s t t n = int(raw_input()) n int(raw_input()) int raw_input() raw_input [0 for i in range(n+1)] for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) [0 for i in range(n+1)] G = [[0 for i in range(n+1)] for j in range(n+1)] G [[0 for i in range(n+1)] for j in range(n+1)] 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 d = [0 for i in range(n+1)] d [0 for i in range(n+1)] 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 f = [0 for i in range(n+1)] f [0 for i in range(n+1)] for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1 i range(n) range n v = map(int, raw_input().split()) v map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(v[1]):
        G[v[0]][v[2+j]] = 1 j range(v[1]) range v[1] v 1 G[v[0]][v[2+j]] = 1 G[v[0]][v[2+j]] [v[0]] G v[0] v 0 v[2+j] v 2+j 2 j 1 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 flag = [0 for i in range(n+1)] flag [0 for i in range(n+1)] for i in range(1, n+1):
    if flag[i] == 0:
        DFS(i, max(f)) i range(1, n+1) range 1 n+1 n 1 if flag[i] == 0:
        DFS(i, max(f)) flag[i] == 0 flag[i] flag i 0 DFS(i, max(f)) DFS i max(f) max f for i in range(1, n+1):
    print(str(i) + " " + str(d[i]) + " " + str(f[i])) i range(1, n+1) range 1 n+1 n 1 print(str(i) + " " + str(d[i]) + " " + str(f[i])) print str(i) + " " + str(d[i]) + " " + str(f[i]) str(i) + " " + str(d[i]) + " " str(i) + " " + str(d[i]) str(i) + " " str(i) str i " " str(d[i]) str d[i] d i " " str(f[i]) str f[i] f i n = int(raw_input()) int(raw_input()) n flag = [0 for i in range(n+1)] [0 for i in range(n+1)] flag def DFS(s, t):
    t += 1
    flag[s] = 1
    d[s] = t
    for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
    f[s] = t + 1 def DFS(s, t):
    t += 1
    flag[s] = 1
    d[s] = t
    for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
    f[s] = t + 1 DFS d = [0 for i in range(n+1)] [0 for i in range(n+1)] d v = map(int, raw_input().split()) map(int, raw_input().split()) v f = [0 for i in range(n+1)] [0 for i in range(n+1)] f G = [[0 for i in range(n+1)] for j in range(n+1)] [[0 for i in range(n+1)] for j in range(n+1)] G
def DFS(s, t):
    t += 1
    flag[s] = 1
    d[s] = t
    for i in range(1, n+1):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i, t)
                t = f[i]
    f[s] = t + 1

n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [0 for i in range(n+1)]
f = [0 for i in range(n+1)]

for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1

flag = [0 for i in range(n+1)]
for i in range(1, n+1):
    if flag[i] == 0:
        DFS(i, max(f))

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