from collections import defaultdict

def dfs(here, connect, visited, answer):
    global time
    answer[here][1] = time
    time += 1
    visited[here] = 1
    for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
    answer[here][2] = time
    time += 1

v_num = int(input())
connect = defaultdict(list)
for _ in range(v_num):
    inp = [int(n) - 1 for n in input().split(" ")]
    connect[inp[0]].extend(sorted(inp[2:]))
answer = [[n + 1 for m in range(3)] for n in range(v_num)]
time = 1
visited = [0 for n in range(v_num)]
for i in range(v_num):
    if not visited[i]:
        dfs(i, connect, visited, answer)
for v in range(v_num):
    print(*answer[v]) from collections import defaultdict def dfs(here, connect, visited, answer):
    global time
    answer[here][1] = time
    time += 1
    visited[here] = 1
    for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
    answer[here][2] = time
    time += 1 dfs global time answer[here][1] = time answer[here][1] [here] answer here 1 time time += 1 time 1 visited[here] = 1 visited[here] visited here 1 for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
     c connect[here] connect here if not visited[c]:
            dfs(c, connect, visited, answer)
     not visited[c] visited[c] visited c dfs(c, connect, visited, answer) dfs c connect visited answer answer[here][2] = time answer[here][2] [here] answer here 2 time time += 1 time 1 here here connect connect visited visited answer answer v_num = int(input()) v_num int(input()) int input() input connect = defaultdict(list) connect defaultdict(list) defaultdict list for _ in range(v_num):
    inp = [int(n) - 1 for n in input().split(" ")]
    connect[inp[0]].extend(sorted(inp[2:])) _ range(v_num) range v_num int(n) - 1 for n in input().split(" ") for n in input().split(" ") n input().split(" ") ().split () input split " " for n in input().split(" ") int(n) - 1 int(n) int n 1 inp = [int(n) - 1 for n in input().split(" ")] inp [int(n) - 1 for n in input().split(" ")] connect[inp[0]].extend(sorted(inp[2:])) [inp[0]].extend [inp[0]] connect inp[0] inp 0 extend sorted(inp[2:]) sorted inp[2:] inp 2: 2 [n + 1 for m in range(3)] for n in range(v_num) for n in range(v_num) n range(v_num) range v_num for n in range(v_num) [n + 1 for m in range(3)] answer = [[n + 1 for m in range(3)] for n in range(v_num)] answer [[n + 1 for m in range(3)] for n in range(v_num)] time = 1 time 1 0 for n in range(v_num) for n in range(v_num) n range(v_num) range v_num for n in range(v_num) 0 visited = [0 for n in range(v_num)] visited [0 for n in range(v_num)] for i in range(v_num):
    if not visited[i]:
        dfs(i, connect, visited, answer) i range(v_num) range v_num if not visited[i]:
        dfs(i, connect, visited, answer) not visited[i] visited[i] visited i dfs(i, connect, visited, answer) dfs i connect visited answer for v in range(v_num):
    print(*answer[v]) v range(v_num) range v_num print(*answer[v]) print *answer[v] answer[v] answer v v_num = int(input()) int(input()) v_num connect = defaultdict(list) defaultdict(list) connect time = 1 1 time answer = [[n + 1 for m in range(3)] for n in range(v_num)] [[n + 1 for m in range(3)] for n in range(v_num)] answer def dfs(here, connect, visited, answer):
    global time
    answer[here][1] = time
    time += 1
    visited[here] = 1
    for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
    answer[here][2] = time
    time += 1 def dfs(here, connect, visited, answer):
    global time
    answer[here][1] = time
    time += 1
    visited[here] = 1
    for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
    answer[here][2] = time
    time += 1 dfs inp = [int(n) - 1 for n in input().split(" ")] [int(n) - 1 for n in input().split(" ")] inp visited = [0 for n in range(v_num)] [0 for n in range(v_num)] visited
from collections import defaultdict

def dfs(here, connect, visited, answer):
    global time
    answer[here][1] = time
    time += 1
    visited[here] = 1
    for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
    answer[here][2] = time
    time += 1

v_num = int(input())
connect = defaultdict(list)
for _ in range(v_num):
    inp = [int(n) - 1 for n in input().split(" ")]
    connect[inp[0]].extend(sorted(inp[2:]))
answer = [[n + 1 for m in range(3)] for n in range(v_num)]
time = 1
visited = [0 for n in range(v_num)]
for i in range(v_num):
    if not visited[i]:
        dfs(i, connect, visited, answer)
for v in range(v_num):
    print(*answer[v])