def disc(s,d):
	ans[d][0] = s
	s += 1
	if main[d][0] != 0:
		for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	ans[d][1] = s
	return s+1

n = int(input())

main = []

for i in range(n):
	a = input().split()
	if int(a[1]) > 0:
		main.append(a[1:])
	else:
		main.append([0])

del a

ans = [[0] * 2 for i in range(n)]

ls = disc(1,0)
for i in range(n):
	if ans[i][0] == 0:
		ls = disc(int(ls),i)


for i in range(n):
	print(str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1]))
 def disc(s,d):
	ans[d][0] = s
	s += 1
	if main[d][0] != 0:
		for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	ans[d][1] = s
	return s+1 disc ans[d][0] = s ans[d][0] [d] ans d 0 s s += 1 s 1 if main[d][0] != 0:
		for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	 main[d][0] != 0 main[d][0] [d] main d 0 0 for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	 l range(1,int(main[d][0])+1) range 1 int(main[d][0])+1 int(main[d][0]) int main[d][0] [d] main d 0 1 if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	 ans[int(main[d][l])-1][0] == 0 ans[int(main[d][l])-1][0] [int(main[d][l])-1] ans int(main[d][l])-1 int(main[d][l]) int main[d][l] [d] main d l 1 0 0 s = disc(int(s),int(main[d][l])-1) s disc(int(s),int(main[d][l])-1) disc int(s) int s int(main[d][l])-1 int(main[d][l]) int main[d][l] [d] main d l 1 ans[d][1] = s ans[d][1] [d] ans d 1 s return s+1 s+1 s 1 s s d d n = int(input()) n int(input()) int input() input main = [] main [] for i in range(n):
	a = input().split()
	if int(a[1]) > 0:
		main.append(a[1:])
	else:
		main.append([0]) i range(n) range n a = input().split() a input().split() ().split () input split if int(a[1]) > 0:
		main.append(a[1:])
	else:
		main.append([0]) int(a[1]) > 0 int(a[1]) int a[1] a 1 0 main.append(a[1:]) main.append main append a[1:] a 1: 1 main.append([0]) main.append main append [0] 0 del a a [0] * 2 for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0] * 2 [0] 0 2 ans = [[0] * 2 for i in range(n)] ans [[0] * 2 for i in range(n)] ls = disc(1,0) ls disc(1,0) disc 1 0 for i in range(n):
	if ans[i][0] == 0:
		ls = disc(int(ls),i) i range(n) range n if ans[i][0] == 0:
		ls = disc(int(ls),i) ans[i][0] == 0 ans[i][0] [i] ans i 0 0 ls = disc(int(ls),i) ls disc(int(ls),i) disc int(ls) int ls i for i in range(n):
	print(str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1])) i range(n) range n print(str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1])) print str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1]) str(i+1) + " " + str(ans[i][0]) + " " str(i+1) + " " + str(ans[i][0]) str(i+1) + " " str(i+1) str i+1 i 1 " " str(ans[i][0]) str ans[i][0] [i] ans i 0 " " str(ans[i][1]) str ans[i][1] [i] ans i 1 ls = disc(int(ls),i) disc(int(ls),i) ls a = input().split() input().split() a def disc(s,d):
	ans[d][0] = s
	s += 1
	if main[d][0] != 0:
		for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	ans[d][1] = s
	return s+1 def disc(s,d):
	ans[d][0] = s
	s += 1
	if main[d][0] != 0:
		for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	ans[d][1] = s
	return s+1 disc n = int(input()) int(input()) n ans = [[0] * 2 for i in range(n)] [[0] * 2 for i in range(n)] ans ls = disc(1,0) disc(1,0) ls main = [] [] main
def disc(s,d):
	ans[d][0] = s
	s += 1
	if main[d][0] != 0:
		for l in range(1,int(main[d][0])+1):
			if ans[int(main[d][l])-1][0] == 0:
				s = disc(int(s),int(main[d][l])-1)
	ans[d][1] = s
	return s+1

n = int(input())

main = []

for i in range(n):
	a = input().split()
	if int(a[1]) > 0:
		main.append(a[1:])
	else:
		main.append([0])

del a

ans = [[0] * 2 for i in range(n)]

ls = disc(1,0)
for i in range(n):
	if ans[i][0] == 0:
		ls = disc(int(ls),i)


for i in range(n):
	print(str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1]))

