from sys import stdin

X = [ 0 for i in range(100) ]
d = [ 0 for i in range(100) ]
f = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]

t = 0

def DFS(i) :
	global t
	t += 1
	d[i] = t
	for j in range(n) :
		if G[i][j] != 0 and d[j] == 0 : DFS(j)
	t += 1
	f[i] = t


n = int(input())
for i in range(n) :
	X[i] = stdin.readline().strip().split()


for i in range(n) :
	for j in range(int(X[i][1])) :
		G[int(X[i][0])-1][int(X[i][j+2])-1] = 1

for i in range(n) :
	if d[i] == 0 : DFS(i)

for i in range(n) : print(i+1,d[i],f[i]) from sys import stdin 0 for i in range(100) for i in range(100) i range(100) range 100 for i in range(100) 0 X = [ 0 for i in range(100) ] X [ 0 for i in range(100) ] 0 for i in range(100) for i in range(100) i range(100) range 100 for i in range(100) 0 d = [ 0 for i in range(100) ] d [ 0 for i in range(100) ] 0 for i in range(100) for i in range(100) i range(100) range 100 for i in range(100) 0 f = [ 0 for i in range(100) ] f [ 0 for i in range(100) ] [ 0 for i in range(100) ] for i in range(100) for i in range(100) i range(100) range 100 for i in range(100) [ 0 for i in range(100) ] G = [[ 0 for i in range(100) ] for i in range(100)] G [[ 0 for i in range(100) ] for i in range(100)] t = 0 t 0 def DFS(i) :
	global t
	t += 1
	d[i] = t
	for j in range(n) :
		if G[i][j] != 0 and d[j] == 0 : DFS(j)
	t += 1
	f[i] = t DFS global t t += 1 t 1 d[i] = t d[i] d i t for j in range(n) :
		if G[i][j] != 0 and d[j] == 0 : DFS(j)
	 j range(n) range n if G[i][j] != 0 and d[j] == 0 : DFS(j)
	 G[i][j] != 0 and d[j] == 0 G[i][j] != 0 G[i][j] [i] G i j 0 d[j] == 0 d[j] d j 0 t += 1 t 1 f[i] = t f[i] f i t i i n = int(input()) n int(input()) int input() input for i in range(n) :
	X[i] = stdin.readline().strip().split() i range(n) range n X[i] = stdin.readline().strip().split() X[i] X i stdin.readline().strip().split() stdin.readline().strip().split stdin.readline().strip() stdin.readline().strip stdin.readline() stdin.readline stdin readline strip split for i in range(n) :
	for j in range(int(X[i][1])) :
		G[int(X[i][0])-1][int(X[i][j+2])-1] = 1 i range(n) range n for j in range(int(X[i][1])) :
		G[int(X[i][0])-1][int(X[i][j+2])-1] = 1 j range(int(X[i][1])) range int(X[i][1]) int X[i][1] [i] X i 1 G[int(X[i][0])-1][int(X[i][j+2])-1] = 1 G[int(X[i][0])-1][int(X[i][j+2])-1] [int(X[i][0])-1] G int(X[i][0])-1 int(X[i][0]) int X[i][0] [i] X i 0 1 int(X[i][j+2])-1 int(X[i][j+2]) int X[i][j+2] [i] X i j+2 j 2 1 1 for i in range(n) :
	if d[i] == 0 : DFS(i) i range(n) range n if d[i] == 0 : DFS(i d[i] == 0 d[i] d i 0 for i in range(n) : print(i+1,d[i],f[i]) i range(n) range n d = [ 0 for i in range(100) ] [ 0 for i in range(100) ] d f = [ 0 for i in range(100) ] [ 0 for i in range(100) ] f n = int(input()) int(input()) n G = [[ 0 for i in range(100) ] for i in range(100)] [[ 0 for i in range(100) ] for i in range(100)] G X = [ 0 for i in range(100) ] [ 0 for i in range(100) ] X t = 0 0 t def DFS(i) :
	global t
	t += 1
	d[i] = t
	for j in range(n) :
		if G[i][j] != 0 and d[j] == 0 : DFS(j)
	t += 1
	f[i] = t def DFS(i) :
	global t
	t += 1
	d[i] = t
	for j in range(n) :
		if G[i][j] != 0 and d[j] == 0 : DFS(j)
	t += 1
	f[i] = t DFS
from sys import stdin

X = [ 0 for i in range(100) ]
d = [ 0 for i in range(100) ]
f = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]

t = 0

def DFS(i) :
	global t
	t += 1
	d[i] = t
	for j in range(n) :
		if G[i][j] != 0 and d[j] == 0 : DFS(j)
	t += 1
	f[i] = t


n = int(input())
for i in range(n) :
	X[i] = stdin.readline().strip().split()


for i in range(n) :
	for j in range(int(X[i][1])) :
		G[int(X[i][0])-1][int(X[i][j+2])-1] = 1

for i in range(n) :
	if d[i] == 0 : DFS(i)

for i in range(n) : print(i+1,d[i],f[i])