N = int(input())

G = [[0] * N for _ in range(N)]
time = 0
times = [{'s': 0, 'f': 0} for _ in range(N)]

for _ in range(N):
    u, n, *K = map(int, input().split())
    for k in K:
        G[u - 1][k - 1] = 1

def dfs(u):
    global time
    time += 1
    times[u]['s'] = time
    for i in range(N):
        if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
    else:
        time += 1
        times[u]['f'] = time

for i in range(N):
    if times[i]['s'] == 0:
        dfs(i)

for i, time in enumerate(times):
    print(i + 1, *time.values())
 N = int(input()) N int(input()) int input() input [0] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0] * N [0] 0 N G = [[0] * N for _ in range(N)] G [[0] * N for _ in range(N)] time = 0 time 0 {'s': 0, 'f': 0} for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) {'s': 0, 'f': 0} 's' 's' 0 'f' 'f' 0 times = [{'s': 0, 'f': 0} for _ in range(N)] times [{'s': 0, 'f': 0} for _ in range(N)] for _ in range(N):
    u, n, *K = map(int, input().split())
    for k in K:
        G[u - 1][k - 1] = 1 _ range(N) range N u, n, *K = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split n *K K for k in K:
        G[u - 1][k - 1] = 1 k K G[u - 1][k - 1] = 1 G[u - 1][k - 1] [u - 1] G u - 1 u 1 k - 1 k 1 1 def dfs(u):
    global time
    time += 1
    times[u]['s'] = time
    for i in range(N):
        if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
    else:
        time += 1
        times[u]['f'] = time dfs global time time += 1 time 1 times[u]['s'] = time times[u]['s'] [u] times u 's' time for i in range(N):
        if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
    else:
        time += 1
        times[u]['f'] = time i range(N) range N if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
     G[u][i] == 1 and times[i]['s'] == 0 G[u][i] == 1 G[u][i] [u] G u i 1 times[i]['s'] == 0 times[i]['s'] [i] times i 's' 0 dfs(i) dfs i time += 1 time 1 times[u]['f'] = time times[u]['f'] [u] times u 'f' time u u for i in range(N):
    if times[i]['s'] == 0:
        dfs(i) i range(N) range N if times[i]['s'] == 0:
        dfs(i) times[i]['s'] == 0 times[i]['s'] [i] times i 's' 0 dfs(i) dfs i for i, time in enumerate(times):
    print(i + 1, *time.values()) i time enumerate(times) enumerate times print(i + 1, *time.values()) print i + 1 i 1 *time.values() time.values() time.values time values u, n, *K = map(int, input().split()) map(int, input().split()) u G = [[0] * N for _ in range(N)] [[0] * N for _ in range(N)] G def dfs(u):
    global time
    time += 1
    times[u]['s'] = time
    for i in range(N):
        if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
    else:
        time += 1
        times[u]['f'] = time def dfs(u):
    global time
    time += 1
    times[u]['s'] = time
    for i in range(N):
        if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
    else:
        time += 1
        times[u]['f'] = time dfs N = int(input()) int(input()) N times = [{'s': 0, 'f': 0} for _ in range(N)] [{'s': 0, 'f': 0} for _ in range(N)] times time = 0 0 time n, *K = map(int, input().split()) map(int, input().split()) n
N = int(input())

G = [[0] * N for _ in range(N)]
time = 0
times = [{'s': 0, 'f': 0} for _ in range(N)]

for _ in range(N):
    u, n, *K = map(int, input().split())
    for k in K:
        G[u - 1][k - 1] = 1

def dfs(u):
    global time
    time += 1
    times[u]['s'] = time
    for i in range(N):
        if G[u][i] == 1 and times[i]['s'] == 0:
            dfs(i)
    else:
        time += 1
        times[u]['f'] = time

for i in range(N):
    if times[i]['s'] == 0:
        dfs(i)

for i, time in enumerate(times):
    print(i + 1, *time.values())

