from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

n = int(input())

graph = []

for _ in range(n):
    tmp = list(map(int, input().split()))

    if tmp[1] == 0:
        graph.append([])
        continue
    else:
        graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2])))

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

time = 1


def dfs(x):
    if d[x] != -1:
        return

    global time

    d[x] = time
    time += 1

    for n in graph[x]:
        dfs(n)

    f[x] = time
    time += 1


for i in range(n):
    dfs(i)

for i in range(n):
    print(i + 1, d[i], f[i])
 from sys import setrecursionlimit setrecursionlimit(10 ** 9) setrecursionlimit 10 ** 9 10 9 n = int(input()) n int(input()) int input() input graph = [] graph [] for _ in range(n):
    tmp = list(map(int, input().split()))

    if tmp[1] == 0:
        graph.append([])
        continue
    else:
        graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2]))) _ range(n) range n tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if tmp[1] == 0:
        graph.append([])
        continue
    else:
        graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2]))) tmp[1] == 0 tmp[1] tmp 1 0 graph.append([]) graph.append graph append [] continue graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2]))) graph.append graph append list(map(lambda x: x - 1, tmp[2: tmp[1] + 2])) list map(lambda x: x - 1, tmp[2: tmp[1] + 2]) map lambda x: x - 1 x - 1 x 1 x tmp[2: tmp[1] + 2] tmp 2: tmp[1] + 2 2 tmp[1] + 2 tmp[1] tmp 1 2 d = [-1] * n d [-1] * n [-1] -1 n f = [-1] * n f [-1] * n [-1] -1 n time = 1 time 1 def dfs(x):
    if d[x] != -1:
        return

    global time

    d[x] = time
    time += 1

    for n in graph[x]:
        dfs(n)

    f[x] = time
    time += 1 dfs if d[x] != -1:
        return

     d[x] != -1 d[x] d x -1 return global time d[x] = time d[x] d x time time += 1 time 1 for n in graph[x]:
        dfs(n)

     n graph[x] graph x dfs(n) dfs n f[x] = time f[x] f x time time += 1 time 1 x x for i in range(n):
    dfs(i) i range(n) range n dfs(i) dfs i 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 d = [-1] * n [-1] * n d f = [-1] * n [-1] * n f time = 1 1 time graph = [] [] graph n = int(input()) int(input()) n tmp = list(map(int, input().split())) list(map(int, input().split())) tmp def dfs(x):
    if d[x] != -1:
        return

    global time

    d[x] = time
    time += 1

    for n in graph[x]:
        dfs(n)

    f[x] = time
    time += 1 def dfs(x):
    if d[x] != -1:
        return

    global time

    d[x] = time
    time += 1

    for n in graph[x]:
        dfs(n)

    f[x] = time
    time += 1 dfs
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

n = int(input())

graph = []

for _ in range(n):
    tmp = list(map(int, input().split()))

    if tmp[1] == 0:
        graph.append([])
        continue
    else:
        graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2])))

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

time = 1


def dfs(x):
    if d[x] != -1:
        return

    global time

    d[x] = time
    time += 1

    for n in graph[x]:
        dfs(n)

    f[x] = time
    time += 1


for i in range(n):
    dfs(i)

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

