#Boost Force  / Backtracking
import sys
input = sys.stdin.readline
d = []
f = []
time = 0
#ทำการ search
def search(r):
    global d,f,time,s
    if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
    for x in s[r]:
        search(x)
    time += 1
    f[r] = time


n = int(input()) #รับค่าจำนวน node ทั้งหมด
s = [[] for i in range(n+1)]
for _ in range(n):
    d = list(map(int,input().split())) #รับข้อมูลทีละบรรทัด split เก็บเป็น int
    #ตน d[0] คือ node ตน 1 คือ ดีกรี ตนตั้งแต่ 2ไป คือ vertex
    s[d[0]] = d[2:]

d = [0 for _ in range(n+1)]
f = [0 for _ in range(n+1)]

for i in range(1,n+1):
    if d[i] == 0:
        search(i)

#แสดง node เวลาที่เจอ และ เวลา finish
for i in range(1,n+1):
    print (i,d[i],f[i])
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline d = [] d [] f = [] f [] time = 0 time 0 def search(r):
    global d,f,time,s
    if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
    for x in s[r]:
        search(x)
    time += 1
    f[r] = time search global d,f,time,s if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
     d[r] == 0 d[r] d r 0 time += 1 time 1 d[r] = time d[r] d r time return for x in s[r]:
        search(x)
     x s[r] s r search(x) search x time += 1 time 1 f[r] = time f[r] f r time r r n = int(input()) n int(input()) int input() input [] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [] s = [[] for i in range(n+1)] s [[] for i in range(n+1)] for _ in range(n):
    d = list(map(int,input().split())) #รับข้อมูลทีละบรรทัด split เก็บเป็น int
    #ตน d[0] คือ node ตน 1 คือ ดีกรี ตนตั้งแต่ 2ไป คือ vertex
    s[d[0]] = d[2:] _ range(n) range n d = list(map(int,input().split())) d list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split s[d[0]] = d[2:] s[d[0]] s d[0] d 0 d[2:] d 2: 2 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 d = [0 for _ in range(n+1)] d [0 for _ in range(n+1)] 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 f = [0 for _ in range(n+1)] f [0 for _ in range(n+1)] for i in range(1,n+1):
    if d[i] == 0:
        search(i)

#แสดง node เวลาที่เจอ และ เวลา finish i range(1,n+1) range 1 n+1 n 1 if d[i] == 0:
        search(i)

#แสดง node เวลาที่เจอ และ เวลา finish d[i] == 0 d[i] d i 0 search(i) search i for i in range(1,n+1):
    print (i,d[i],f[i]) i range(1,n+1) range 1 n+1 n 1 print (i,d[i],f[i]) print i d[i] d i f[i] f i f = [0 for _ in range(n+1)] [0 for _ in range(n+1)] f input = sys.stdin.readline sys.stdin.readline input f = [] [] f d = [] [] d s = [[] for i in range(n+1)] [[] for i in range(n+1)] s d = [0 for _ in range(n+1)] [0 for _ in range(n+1)] d n = int(input()) int(input()) n d = list(map(int,input().split())) list(map(int,input().split())) d def search(r):
    global d,f,time,s
    if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
    for x in s[r]:
        search(x)
    time += 1
    f[r] = time def search(r):
    global d,f,time,s
    if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
    for x in s[r]:
        search(x)
    time += 1
    f[r] = time search time = 0 0 time
#Boost Force  / Backtracking
import sys
input = sys.stdin.readline
d = []
f = []
time = 0
#ทำการ search
def search(r):
    global d,f,time,s
    if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
    for x in s[r]:
        search(x)
    time += 1
    f[r] = time


n = int(input()) #รับค่าจำนวน node ทั้งหมด
s = [[] for i in range(n+1)]
for _ in range(n):
    d = list(map(int,input().split())) #รับข้อมูลทีละบรรทัด split เก็บเป็น int
    #ตน d[0] คือ node ตน 1 คือ ดีกรี ตนตั้งแต่ 2ไป คือ vertex
    s[d[0]] = d[2:]

d = [0 for _ in range(n+1)]
f = [0 for _ in range(n+1)]

for i in range(1,n+1):
    if d[i] == 0:
        search(i)

#แสดง node เวลาที่เจอ และ เวลา finish
for i in range(1,n+1):
    print (i,d[i],f[i])

