
def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n

time = 0
for i in range(n):
    if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(n, i, time)

for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time DFS for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
     j range(n) range n if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
     A[i][j] == 1 and d[j] == 0 A[i][j] == 1 A[i][j] [i] A i j 1 d[j] == 0 d[j] d j 0 time = time + 1 time time + 1 time 1 d[j] = time d[j] d j time time = DFS(n, j, time) time DFS(n, j, time) DFS n j time time = time + 1 time time + 1 time 1 f[i] = time f[i] f i time return time time n = 1 n 1 i = 0 i 0 time = 1 time 1 n = int(raw_input()) n int(raw_input()) int raw_input() raw_input A = [0] * n A [0] * n [0] 0 n for i in range(n):
    A[i] = [0] * n i range(n) range n A[i] = [0] * n A[i] A i [0] * n [0] 0 n for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1 i range(n) range n value = map(int, raw_input().split()) value map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split u = value[0] - 1 u value[0] - 1 value[0] value 0 1 k = value[1] k value[1] value 1 nodes = value[2:] nodes value[2:] value 2: 2 for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1 j range(k) range k v = nodes[j] - 1 v nodes[j] - 1 nodes[j] nodes j 1 A[u][v] = 1 A[u][v] [u] A u v 1 d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n time = 0 time 0 for i in range(n):
    if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(n, i, time) i range(n) range n if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(n, i, time) d[i] == 0 d[i] d i 0 time = time + 1 time time + 1 time 1 d[i] = time d[i] d i time time = DFS(n, i, time) time DFS(n, i, time) DFS n i time for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) i range(n) range n print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) print str(i + 1) + " " + str(d[i]) + " " + str(f[i]) str(i + 1) + " " + str(d[i]) + " " str(i + 1) + " " + str(d[i]) str(i + 1) + " " str(i + 1) str i + 1 i 1 " " str(d[i]) str d[i] d i " " str(f[i]) str f[i] f i v = nodes[j] - 1 nodes[j] - 1 v time = 0 0 time n = int(raw_input()) int(raw_input()) n f = [0] * n [0] * n f d = [0] * n [0] * n d def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time DFS nodes = value[2:] value[2:] nodes u = value[0] - 1 value[0] - 1 u time = time + 1 time + 1 time A = [0] * n [0] * n A value = map(int, raw_input().split()) map(int, raw_input().split()) value k = value[1] value[1] k time = DFS(n, i, time) DFS(n, i, time) time

def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n

time = 0
for i in range(n):
    if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(n, i, time)

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