import sys

#sys.setrecursionlimit(100000)
u=[]
k=[]
v=[]

time = 0

n=int(sys.stdin.readline().strip())
yattayatu=[False for i in range(n)]

s=[0 for i in range(n)]
f=[0 for i in range(n)]

for i in range(n):
	inp = sys.stdin.readline().strip().split(" ")
	inp = list(map(lambda x: int(x), inp))
	u.append(inp[0])
	k.append(inp[1])
	v.append(inp[2:])


def func(nodeid):
	global time
	if(yattayatu[nodeid-1]==True):
		return
	yattayatu[nodeid-1]=True
	time += 1
	s[nodeid-1] = time
	for i in range(k[nodeid-1]):
		func(v[nodeid-1][i])
	time +=1
	f[nodeid-1]=time
	return

for i in range(n):
	func(i+1)

for i in range(n):
	print(str(i+1)+" "+str(s[i])+" "+str(f[i])) import sys sys u=[] u [] k=[] k [] v=[] v [] time = 0 time 0 n=int(sys.stdin.readline().strip()) n int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip False for i in range(n) for i in range(n) i range(n) range n for i in range(n) False yattayatu=[False for i in range(n)] yattayatu [False for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 s=[0 for i in range(n)] s [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f=[0 for i in range(n)] f [0 for i in range(n)] for i in range(n):
	inp = sys.stdin.readline().strip().split(" ")
	inp = list(map(lambda x: int(x), inp))
	u.append(inp[0])
	k.append(inp[1])
	v.append(inp[2:]) i range(n) range n inp = sys.stdin.readline().strip().split(" ") inp sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " inp = list(map(lambda x: int(x), inp)) inp list(map(lambda x: int(x), inp)) list map(lambda x: int(x), inp) map lambda x: int(x) int(x) int x x inp u.append(inp[0]) u.append u append inp[0] inp 0 k.append(inp[1]) k.append k append inp[1] inp 1 v.append(inp[2:]) v.append v append inp[2:] inp 2: 2 def func(nodeid):
	global time
	if(yattayatu[nodeid-1]==True):
		return
	yattayatu[nodeid-1]=True
	time += 1
	s[nodeid-1] = time
	for i in range(k[nodeid-1]):
		func(v[nodeid-1][i])
	time +=1
	f[nodeid-1]=time
	return func global time if(yattayatu[nodeid-1]==True):
		return
	 yattayatu[nodeid-1]==True yattayatu[nodeid-1] yattayatu nodeid-1 nodeid 1 True return yattayatu[nodeid-1]=True yattayatu[nodeid-1] yattayatu nodeid-1 nodeid 1 True time += 1 time 1 s[nodeid-1] = time s[nodeid-1] s nodeid-1 nodeid 1 time for i in range(k[nodeid-1]):
		func(v[nodeid-1][i])
	 i range(k[nodeid-1]) range k[nodeid-1] k nodeid-1 nodeid 1 func(v[nodeid-1][i]) func v[nodeid-1][i] [nodeid-1] v nodeid-1 nodeid 1 i time +=1 time 1 f[nodeid-1]=time f[nodeid-1] f nodeid-1 nodeid 1 time return nodeid nodeid for i in range(n):
	func(i+1) i range(n) range n func(i+1) func i+1 i 1 for i in range(n):
	print(str(i+1)+" "+str(s[i])+" "+str(f[i])) i range(n) range n print(str(i+1)+" "+str(s[i])+" "+str(f[i])) print str(i+1)+" "+str(s[i])+" "+str(f[i]) str(i+1)+" "+str(s[i])+" " str(i+1)+" "+str(s[i]) str(i+1)+" " str(i+1) str i+1 i 1 " " str(s[i]) str s[i] s i " " str(f[i]) str f[i] f i time = 0 0 time k=[] [] k f=[0 for i in range(n)] [0 for i in range(n)] f inp = list(map(lambda x: int(x), inp)) list(map(lambda x: int(x), inp)) inp u=[] [] u n=int(sys.stdin.readline().strip()) int(sys.stdin.readline().strip()) n s=[0 for i in range(n)] [0 for i in range(n)] s def func(nodeid):
	global time
	if(yattayatu[nodeid-1]==True):
		return
	yattayatu[nodeid-1]=True
	time += 1
	s[nodeid-1] = time
	for i in range(k[nodeid-1]):
		func(v[nodeid-1][i])
	time +=1
	f[nodeid-1]=time
	return def func(nodeid):
	global time
	if(yattayatu[nodeid-1]==True):
		return
	yattayatu[nodeid-1]=True
	time += 1
	s[nodeid-1] = time
	for i in range(k[nodeid-1]):
		func(v[nodeid-1][i])
	time +=1
	f[nodeid-1]=time
	return func inp = sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split(" ") inp v=[] [] v yattayatu=[False for i in range(n)] [False for i in range(n)] yattayatu
import sys

#sys.setrecursionlimit(100000)
u=[]
k=[]
v=[]

time = 0

n=int(sys.stdin.readline().strip())
yattayatu=[False for i in range(n)]

s=[0 for i in range(n)]
f=[0 for i in range(n)]

for i in range(n):
	inp = sys.stdin.readline().strip().split(" ")
	inp = list(map(lambda x: int(x), inp))
	u.append(inp[0])
	k.append(inp[1])
	v.append(inp[2:])


def func(nodeid):
	global time
	if(yattayatu[nodeid-1]==True):
		return
	yattayatu[nodeid-1]=True
	time += 1
	s[nodeid-1] = time
	for i in range(k[nodeid-1]):
		func(v[nodeid-1][i])
	time +=1
	f[nodeid-1]=time
	return

for i in range(n):
	func(i+1)

for i in range(n):
	print(str(i+1)+" "+str(s[i])+" "+str(f[i]))