import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

n = int(input())
info = [list(map(int, input().split())) for _ in range(n)]
ans = [[i + 1, -1, -1] for i in range(n)]
check = [0 for _ in range(n)]
time = 1


def dfs(num):
    check[num] = 1
    global time
    if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
    for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
    if ans[num][2] == -1:
        ans[num][2] = time
        time += 1


for i in range(n):
    if check[i] == 0:
        dfs(i)

for i in ans:
    i = list(map(str, i))
    print(" ".join(i))
 import sys sys import math math import string string import fractions fractions import random random from operator import itemgetter import itertools itertools from collections import deque import copy copy import heapq heapq import bisect bisect MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = float('inf') INF float('inf') float 'inf' input = lambda: sys.stdin.readline().strip() input lambda: sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 n = int(input()) n int(input()) int input() input list(map(int, input().split())) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split info = [list(map(int, input().split())) for _ in range(n)] info [list(map(int, input().split())) for _ in range(n)] [i + 1, -1, -1] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [i + 1, -1, -1] i + 1 i 1 -1 -1 ans = [[i + 1, -1, -1] for i in range(n)] ans [[i + 1, -1, -1] for i in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 check = [0 for _ in range(n)] check [0 for _ in range(n)] time = 1 time 1 def dfs(num):
    check[num] = 1
    global time
    if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
    for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
    if ans[num][2] == -1:
        ans[num][2] = time
        time += 1 dfs check[num] = 1 check[num] check num 1 global time if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
     ans[num][1] == -1 ans[num][1] [num] ans num 1 -1 ans[num][1] = time ans[num][1] [num] ans num 1 time time += 1 time 1 for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
     i info[num][2:] [num] info num 2: 2 if check[i - 1] == 0:
            dfs(i - 1)
     check[i - 1] == 0 check[i - 1] check i - 1 i 1 0 dfs(i - 1) dfs i - 1 i 1 if ans[num][2] == -1:
        ans[num][2] = time
        time += 1 ans[num][2] == -1 ans[num][2] [num] ans num 2 -1 ans[num][2] = time ans[num][2] [num] ans num 2 time time += 1 time 1 num num for i in range(n):
    if check[i] == 0:
        dfs(i) i range(n) range n if check[i] == 0:
        dfs(i) check[i] == 0 check[i] check i 0 dfs(i) dfs i for i in ans:
    i = list(map(str, i))
    print(" ".join(i)) i ans i = list(map(str, i)) i list(map(str, i)) list map(str, i) map str i print(" ".join(i)) print " ".join(i) " ".join " " join i time = 1 1 time def dfs(num):
    check[num] = 1
    global time
    if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
    for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
    if ans[num][2] == -1:
        ans[num][2] = time
        time += 1 def dfs(num):
    check[num] = 1
    global time
    if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
    for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
    if ans[num][2] == -1:
        ans[num][2] = time
        time += 1 dfs n = int(input()) int(input()) n info = [list(map(int, input().split())) for _ in range(n)] [list(map(int, input().split())) for _ in range(n)] info check = [0 for _ in range(n)] [0 for _ in range(n)] check MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD ans = [[i + 1, -1, -1] for i in range(n)] [[i + 1, -1, -1] for i in range(n)] ans INF = float('inf') float('inf') INF input = lambda: sys.stdin.readline().strip() lambda: sys.stdin.readline().strip() input i = list(map(str, i)) list(map(str, i)) i
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

n = int(input())
info = [list(map(int, input().split())) for _ in range(n)]
ans = [[i + 1, -1, -1] for i in range(n)]
check = [0 for _ in range(n)]
time = 1


def dfs(num):
    check[num] = 1
    global time
    if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
    for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
    if ans[num][2] == -1:
        ans[num][2] = time
        time += 1


for i in range(n):
    if check[i] == 0:
        dfs(i)

for i in ans:
    i = list(map(str, i))
    print(" ".join(i))

