n = int(input())

points = []
seen = []
find_time = []
end_time = []
for _ in range(n):
    input_text = list(map(int, input().split()))
    u, k, v_list = input_text[0], input_text[1], input_text[2:]
    seen.append(False)
    points.append(v_list)
    find_time.append(0)
    end_time.append(0)

count = [0]


def dfs(graph, v, count):
    seen[v] = True
    find_time[v] = count[0]
    for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
    count[0] += 1
    end_time[v] = count[0]


for index, seen_point in enumerate(seen):
    if seen_point:
        pass
    else:
        count[0] += 1
        dfs(points, index, count)
# print(find_time)
# print(end_time)


count = 1
for f, e in zip(find_time, end_time):
    print(count, f, e)
    count += 1
 n = int(input()) n int(input()) int input() input points = [] points [] seen = [] seen [] find_time = [] find_time [] end_time = [] end_time [] for _ in range(n):
    input_text = list(map(int, input().split()))
    u, k, v_list = input_text[0], input_text[1], input_text[2:]
    seen.append(False)
    points.append(v_list)
    find_time.append(0)
    end_time.append(0) _ range(n) range n input_text = list(map(int, input().split())) input_text list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u, k, v_list = input_text[0], input_text[1], input_text[2:] u input_text[0] input_text 0 k input_text[1] input_text 1 v_list input_text[2:] input_text 2: 2 seen.append(False) seen.append seen append False points.append(v_list) points.append points append v_list find_time.append(0) find_time.append find_time append 0 end_time.append(0) end_time.append end_time append 0 count = [0] count [0] 0 def dfs(graph, v, count):
    seen[v] = True
    find_time[v] = count[0]
    for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
    count[0] += 1
    end_time[v] = count[0] dfs seen[v] = True seen[v] seen v True find_time[v] = count[0] find_time[v] find_time v count[0] count 0 for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
     next_v graph[v] graph v if seen[next_v - 1]:
            continue
         seen[next_v - 1] seen next_v - 1 next_v 1 continue count[0] += 1 count[0] count 0 1 dfs(graph, next_v - 1, count) dfs graph next_v - 1 next_v 1 count count[0] += 1 count[0] count 0 1 end_time[v] = count[0] end_time[v] end_time v count[0] count 0 graph graph v v count count for index, seen_point in enumerate(seen):
    if seen_point:
        pass
    else:
        count[0] += 1
        dfs(points, index, count)
# print(find_time)
# print(end_time) index seen_point enumerate(seen) enumerate seen if seen_point:
        pass
    else:
        count[0] += 1
        dfs(points, index, count)
# print(find_time)
# print(end_time) seen_point count[0] += 1 count[0] count 0 1 dfs(points, index, count) dfs points index count count = 1 count 1 for f, e in zip(find_time, end_time):
    print(count, f, e)
    count += 1 f e zip(find_time, end_time) zip find_time end_time print(count, f, e) print count f e count += 1 count 1 count = [0] [0] count end_time = [] [] end_time count += 1 1 count seen = [] [] seen def dfs(graph, v, count):
    seen[v] = True
    find_time[v] = count[0]
    for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
    count[0] += 1
    end_time[v] = count[0] def dfs(graph, v, count):
    seen[v] = True
    find_time[v] = count[0]
    for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
    count[0] += 1
    end_time[v] = count[0] dfs points = [] [] points input_text = list(map(int, input().split())) list(map(int, input().split())) input_text k, v_list = input_text[0], input_text[1], input_text[2:] input_text[1] k count = 1 1 count v_list = input_text[0], input_text[1], input_text[2:] input_text[2:] v_list u, k, v_list = input_text[0], input_text[1], input_text[2:] input_text[0] u n = int(input()) int(input()) n find_time = [] [] find_time
n = int(input())

points = []
seen = []
find_time = []
end_time = []
for _ in range(n):
    input_text = list(map(int, input().split()))
    u, k, v_list = input_text[0], input_text[1], input_text[2:]
    seen.append(False)
    points.append(v_list)
    find_time.append(0)
    end_time.append(0)

count = [0]


def dfs(graph, v, count):
    seen[v] = True
    find_time[v] = count[0]
    for next_v in graph[v]:
        if seen[next_v - 1]:
            continue
        count[0] += 1
        dfs(graph, next_v - 1, count)
    count[0] += 1
    end_time[v] = count[0]


for index, seen_point in enumerate(seen):
    if seen_point:
        pass
    else:
        count[0] += 1
        dfs(points, index, count)
# print(find_time)
# print(end_time)


count = 1
for f, e in zip(find_time, end_time):
    print(count, f, e)
    count += 1

