N = int(input())

nodes = [tuple(map(int, input().split(' '))) for _ in range(N)]
d = [-1 for _ in range(N + 1)]
f = [-1 for _ in range(N + 1)]

clock = 0


def dfs(node):
    global clock
    if d[node] == -1:
        clock += 1
        d[node] = clock
    neighbors = sorted(nodes[node - 1][2:])

    for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

    if f[node] == -1:
        clock += 1
        f[node] = clock


for i in range(1, N + 1):
    dfs(i)
    print(i, d[i], f[i])
 N = int(input()) N int(input()) int input() input tuple(map(int, input().split(' '))) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) tuple(map(int, input().split(' '))) tuple map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' nodes = [tuple(map(int, input().split(' '))) for _ in range(N)] nodes [tuple(map(int, input().split(' '))) for _ in range(N)] -1 for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) -1 d = [-1 for _ in range(N + 1)] d [-1 for _ in range(N + 1)] -1 for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) -1 f = [-1 for _ in range(N + 1)] f [-1 for _ in range(N + 1)] clock = 0 clock 0 def dfs(node):
    global clock
    if d[node] == -1:
        clock += 1
        d[node] = clock
    neighbors = sorted(nodes[node - 1][2:])

    for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

    if f[node] == -1:
        clock += 1
        f[node] = clock dfs global clock if d[node] == -1:
        clock += 1
        d[node] = clock
     d[node] == -1 d[node] d node -1 clock += 1 clock 1 d[node] = clock d[node] d node clock neighbors = sorted(nodes[node - 1][2:]) neighbors sorted(nodes[node - 1][2:]) sorted nodes[node - 1][2:] [node - 1] nodes node - 1 node 1 2: 2 for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

     neighbor neighbors if d[neighbor] == -1:
            dfs(neighbor)

     d[neighbor] == -1 d[neighbor] d neighbor -1 dfs(neighbor) dfs neighbor if f[node] == -1:
        clock += 1
        f[node] = clock f[node] == -1 f[node] f node -1 clock += 1 clock 1 f[node] = clock f[node] f node clock node node for i in range(1, N + 1):
    dfs(i)
    print(i, d[i], f[i]) i range(1, N + 1) range 1 N + 1 N 1 dfs(i) dfs i print(i, d[i], f[i]) print i d[i] d i f[i] f i d = [-1 for _ in range(N + 1)] [-1 for _ in range(N + 1)] d f = [-1 for _ in range(N + 1)] [-1 for _ in range(N + 1)] f def dfs(node):
    global clock
    if d[node] == -1:
        clock += 1
        d[node] = clock
    neighbors = sorted(nodes[node - 1][2:])

    for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

    if f[node] == -1:
        clock += 1
        f[node] = clock def dfs(node):
    global clock
    if d[node] == -1:
        clock += 1
        d[node] = clock
    neighbors = sorted(nodes[node - 1][2:])

    for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

    if f[node] == -1:
        clock += 1
        f[node] = clock dfs clock = 0 0 clock N = int(input()) int(input()) N nodes = [tuple(map(int, input().split(' '))) for _ in range(N)] [tuple(map(int, input().split(' '))) for _ in range(N)] nodes
N = int(input())

nodes = [tuple(map(int, input().split(' '))) for _ in range(N)]
d = [-1 for _ in range(N + 1)]
f = [-1 for _ in range(N + 1)]

clock = 0


def dfs(node):
    global clock
    if d[node] == -1:
        clock += 1
        d[node] = clock
    neighbors = sorted(nodes[node - 1][2:])

    for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

    if f[node] == -1:
        clock += 1
        f[node] = clock


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

