n=int(input())

next=[[] for i in range(n)]
for i in range(n):
	l=list(map(int,input().split()))
	u=l[0]
	k=l[1]
	for j in range(2,k+2):
		next[u-1].append(l[j]-1)

stk=[]
stk.append(0)
time=1
d=[0 for i in range(n)]
f=[0 for i in range(n)]
know=[0 for i in range(n)]

def dfs(x):
	global time
	know[x]=1
	d[x]=time
	time+=1
	for n in next[x]:
		if know[n]==0:
			dfs(n)
	f[x]=time
	time+=1
	
for i in range(n):
	if know[i]==0:
		dfs(i)

for i in range(n):
	out=[]
	out.append(i+1)
	out.append(d[i])
	out.append(f[i])
	print(*out) n=int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] next=[[] for i in range(n)] next [[] for i in range(n)] for i in range(n):
	l=list(map(int,input().split()))
	u=l[0]
	k=l[1]
	for j in range(2,k+2):
		next[u-1].append(l[j]-1) i range(n) range n l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split u=l[0] u l[0] l 0 k=l[1] k l[1] l 1 for j in range(2,k+2):
		next[u-1].append(l[j]-1) j range(2,k+2) range 2 k+2 k 2 next[u-1].append(l[j]-1) [u-1].append [u-1] next u-1 u 1 append l[j]-1 l[j] l j 1 stk=[] stk [] stk.append(0) stk.append stk append 0 time=1 time 1 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d=[0 for i in range(n)] d [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)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 know=[0 for i in range(n)] know [0 for i in range(n)] def dfs(x):
	global time
	know[x]=1
	d[x]=time
	time+=1
	for n in next[x]:
		if know[n]==0:
			dfs(n)
	f[x]=time
	time+=1
	 dfs global time know[x]=1 know[x] know x 1 d[x]=time d[x] d x time time+=1 time 1 for n in next[x]:
		if know[n]==0:
			dfs(n)
	 n next[x] next x if know[n]==0:
			dfs(n)
	 know[n]==0 know[n] know n 0 dfs(n) dfs n f[x]=time f[x] f x time time+=1 time 1 x x for i in range(n):
	if know[i]==0:
		dfs(i) i range(n) range n if know[i]==0:
		dfs(i) know[i]==0 know[i] know i 0 dfs(i) dfs i for i in range(n):
	out=[]
	out.append(i+1)
	out.append(d[i])
	out.append(f[i])
	print(*out) i range(n) range n out=[] out [] out.append(i+1) out.append out append i+1 i 1 out.append(d[i]) out.append out append d[i] d i out.append(f[i]) out.append out append f[i] f i print(*out) print *out out stk=[] [] stk know=[0 for i in range(n)] [0 for i in range(n)] know out=[] [] out n=int(input()) int(input()) n f=[0 for i in range(n)] [0 for i in range(n)] f def dfs(x):
	global time
	know[x]=1
	d[x]=time
	time+=1
	for n in next[x]:
		if know[n]==0:
			dfs(n)
	f[x]=time
	time+=1
	 def dfs(x):
	global time
	know[x]=1
	d[x]=time
	time+=1
	for n in next[x]:
		if know[n]==0:
			dfs(n)
	f[x]=time
	time+=1
	 dfs next=[[] for i in range(n)] [[] for i in range(n)] next u=l[0] l[0] u time=1 1 time l=list(map(int,input().split())) list(map(int,input().split())) l k=l[1] l[1] k d=[0 for i in range(n)] [0 for i in range(n)] d
n=int(input())

next=[[] for i in range(n)]
for i in range(n):
	l=list(map(int,input().split()))
	u=l[0]
	k=l[1]
	for j in range(2,k+2):
		next[u-1].append(l[j]-1)

stk=[]
stk.append(0)
time=1
d=[0 for i in range(n)]
f=[0 for i in range(n)]
know=[0 for i in range(n)]

def dfs(x):
	global time
	know[x]=1
	d[x]=time
	time+=1
	for n in next[x]:
		if know[n]==0:
			dfs(n)
	f[x]=time
	time+=1
	
for i in range(n):
	if know[i]==0:
		dfs(i)

for i in range(n):
	out=[]
	out.append(i+1)
	out.append(d[i])
	out.append(f[i])
	print(*out)
