import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def dfs(start, graph, visited, time):
    visited[start][0] = time
    for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
    return time


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[False] * N for _ in range(N)]
    visited = [[-1, -1] for _ in range(N)]

    for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

    time = 0
    for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
    for n in range(N):
        print(n + 1, *visited[n])


if __name__ == '__main__':
    main()
 import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array sys os math bisect itertools collections heapq queue copy array sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 ii = lambda: int(sys.stdin.buffer.readline().rstrip()) ii lambda: int(sys.stdin.buffer.readline().rstrip()) int(sys.stdin.buffer.readline().rstrip()) int sys.stdin.buffer.readline().rstrip() sys.stdin.buffer.readline().rstrip sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline rstrip il = lambda: list(map(int, sys.stdin.buffer.readline().split())) il lambda: list(map(int, sys.stdin.buffer.readline().split())) list(map(int, sys.stdin.buffer.readline().split())) list map(int, sys.stdin.buffer.readline().split()) map int sys.stdin.buffer.readline().split() sys.stdin.buffer.readline().split sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline split fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) fl lambda: list(map(float, sys.stdin.buffer.readline().split())) list(map(float, sys.stdin.buffer.readline().split())) list map(float, sys.stdin.buffer.readline().split()) map float sys.stdin.buffer.readline().split() sys.stdin.buffer.readline().split sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline split int(sys.stdin.buffer.readline().rstrip()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(sys.stdin.buffer.readline().rstrip()) int sys.stdin.buffer.readline().rstrip() sys.stdin.buffer.readline().rstrip sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline rstrip iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iln lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] n iss = lambda: sys.stdin.buffer.readline().decode().rstrip() iss lambda: sys.stdin.buffer.readline().decode().rstrip() sys.stdin.buffer.readline().decode().rstrip() sys.stdin.buffer.readline().decode().rstrip sys.stdin.buffer.readline().decode() sys.stdin.buffer.readline().decode sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline decode rstrip sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) sl lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) list(map(str, sys.stdin.buffer.readline().decode().split())) list map(str, sys.stdin.buffer.readline().decode().split()) map str sys.stdin.buffer.readline().decode().split() sys.stdin.buffer.readline().decode().split sys.stdin.buffer.readline().decode() sys.stdin.buffer.readline().decode sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline decode split sys.stdin.buffer.readline().decode().rstrip() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) sys.stdin.buffer.readline().decode().rstrip() sys.stdin.buffer.readline().decode().rstrip sys.stdin.buffer.readline().decode() sys.stdin.buffer.readline().decode sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline decode rstrip isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] isn lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] n lcm = lambda x, y: (x * y) // math.gcd(x, y) lcm lambda x, y: (x * y) // math.gcd(x, y) (x * y) // math.gcd(x, y) x * y x y math.gcd(x, y) math.gcd math gcd x y x y MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 MAX = float('inf') MAX float('inf') float 'inf' def dfs(start, graph, visited, time):
    visited[start][0] = time
    for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
    return time dfs visited[start][0] = time visited[start][0] [start] visited start 0 time for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
     next range(len(graph[start])) range len(graph[start]) len graph[start] graph start if not graph[start][next]: continue
         not graph[start][next] graph[start][next] [start] graph start next if visited[next][0] != -1: continue
         visited[next][0] != -1 visited[next][0] [next] visited next 0 -1 time += 1 time 1 time = dfs(next, graph, visited, time) time dfs(next, graph, visited, time) dfs next graph visited time time += 1 time 1 visited[start][1] = time visited[start][1] [start] visited start 1 time return time time start start graph graph visited visited time time def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[False] * N for _ in range(N)]
    visited = [[-1, -1] for _ in range(N)]

    for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

    time = 0
    for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
    for n in range(N):
        print(n + 1, *visited[n]) main if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

     os.getenv("LOCAL") os.getenv os getenv "LOCAL" sys.stdin = open("input.txt", "r") sys.stdin sys stdin open("input.txt", "r") open "input.txt" "r" N = ii() N ii() ii [False] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [False] * N [False] False N G = [[False] * N for _ in range(N)] G [[False] * N for _ in range(N)] [-1, -1] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [-1, -1] -1 -1 visited = [[-1, -1] for _ in range(N)] visited [[-1, -1] for _ in range(N)] for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

     n range(N) range N u, k, *V = il() u il() il k *V V for v in V:
            G[n][v - 1] = True

     v V G[n][v - 1] = True G[n][v - 1] [n] G n v - 1 v 1 True time = 0 time 0 for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
     n range(N) range N if visited[n][0] != -1: continue
         visited[n][0] != -1 visited[n][0] [n] visited n 0 -1 time += 1 time 1 time = dfs(n, G, visited, time) time dfs(n, G, visited, time) dfs n G visited time for n in range(N):
        print(n + 1, *visited[n]) n range(N) range N print(n + 1, *visited[n]) print n + 1 n 1 *visited[n] visited[n] visited n if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def dfs(start, graph, visited, time):
    visited[start][0] = time
    for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
    return time def dfs(start, graph, visited, time):
    visited[start][0] = time
    for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
    return time dfs fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) lambda: list(map(float, sys.stdin.buffer.readline().split())) fl iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iln iss = lambda: sys.stdin.buffer.readline().decode().rstrip() lambda: sys.stdin.buffer.readline().decode().rstrip() iss isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] isn MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD il = lambda: list(map(int, sys.stdin.buffer.readline().split())) lambda: list(map(int, sys.stdin.buffer.readline().split())) il ii = lambda: int(sys.stdin.buffer.readline().rstrip()) lambda: int(sys.stdin.buffer.readline().rstrip()) ii sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) sl MAX = float('inf') float('inf') MAX lcm = lambda x, y: (x * y) // math.gcd(x, y) lambda x, y: (x * y) // math.gcd(x, y) lcm def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[False] * N for _ in range(N)]
    visited = [[-1, -1] for _ in range(N)]

    for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

    time = 0
    for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
    for n in range(N):
        print(n + 1, *visited[n]) def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[False] * N for _ in range(N)]
    visited = [[-1, -1] for _ in range(N)]

    for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

    time = 0
    for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
    for n in range(N):
        print(n + 1, *visited[n]) main
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def dfs(start, graph, visited, time):
    visited[start][0] = time
    for next in range(len(graph[start])):
        if not graph[start][next]: continue
        if visited[next][0] != -1: continue
        time += 1
        time = dfs(next, graph, visited, time)
    else:
        time += 1
        visited[start][1] = time
    return time


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[False] * N for _ in range(N)]
    visited = [[-1, -1] for _ in range(N)]

    for n in range(N):
        u, k, *V = il()
        for v in V:
            G[n][v - 1] = True

    time = 0
    for n in range(N):
        if visited[n][0] != -1: continue
        time += 1
        time = dfs(n, G, visited, time)
    for n in range(N):
        print(n + 1, *visited[n])


if __name__ == '__main__':
    main()

