n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1
        # A[int(j)-1][int(u)-1] = 1

# for row in A:
#     msg = ' '.join(map(str, row))
#     # print(msg)

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

t = 0

# recursive


def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
            


for i in range(n):
    if d[i] == -1:
        # print('start from:', str(i))
        dfs(i)


for i in range(n):
    print(str(i+1), str(d[i]), str(f[i])) 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)] A = [[0 for i in range(n)] for j in range(n)] A [[0 for i in range(n)] for j in range(n)] for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1
        # A[int(j)-1][int(u)-1] = 1

# for row in A:
#     msg = ' '.join(map(str, row))
#     # print(msg) i range(n) range n u, k, *v = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *v v for j in v:
        A[int(u)-1][int(j)-1] = 1
        # A[int(j)-1][int(u)-1] = 1

# for row in A:
#     msg = ' '.join(map(str, row))
#     # print(msg) j v A[int(u)-1][int(j)-1] = 1 A[int(u)-1][int(j)-1] [int(u)-1] A int(u)-1 int(u) int u 1 int(j)-1 int(j) int j 1 1 d = [-1] * n d [-1] * n [-1] -1 n f = [-1] * n f [-1] * n [-1] -1 n t = 0 t 0 def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
             dfs global t t += 1 t 1 d[u] = t d[u] d u t for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
     i range(len(A[u])) range len(A[u]) len A[u] A u if A[u][i] == 1 and d[i] == -1:
            dfs(i)
     A[u][i] == 1 and d[i] == -1 A[u][i] == 1 A[u][i] [u] A u i 1 d[i] == -1 d[i] d i -1 dfs(i) dfs i t += 1 t 1 f[u] = t f[u] f u t u u for i in range(n):
    if d[i] == -1:
        # print('start from:', str(i))
        dfs(i) i range(n) range n if d[i] == -1:
        # print('start from:', str(i))
        dfs(i) d[i] == -1 d[i] d i -1 dfs(i) dfs i 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 i+1 i 1 str(d[i]) str d[i] d i str(f[i]) str f[i] f i f = [-1] * n [-1] * n f n = int(input()) int(input()) n u, k, *v = list(map(int, input().split())) list(map(int, input().split())) u A = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] A d = [-1] * n [-1] * n d t = 0 0 t k, *v = list(map(int, input().split())) list(map(int, input().split())) k def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
             def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
             dfs
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1
        # A[int(j)-1][int(u)-1] = 1

# for row in A:
#     msg = ' '.join(map(str, row))
#     # print(msg)

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

t = 0

# recursive


def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
            


for i in range(n):
    if d[i] == -1:
        # print('start from:', str(i))
        dfs(i)


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