import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
graph = list()
for i in range(N):
  x = list(map(int, input().split()))
  graph.append(x[2:])

start = [0] * N
end = [0] * N
visited = [False] * N
time = 0
def dfs(n):
  if visited[n]:
    return
  visited[n] = True
  global time
  time += 1
  start[n] = time
  for i in graph[n]:
    dfs(i-1)
  time += 1
  end[n] = time

for i in range(N):
  dfs(i)
for i in range(N):
  print(i+1, start[i], end[i]) import sys sys sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 N = int(input()) N int(input()) int input() input graph = list() graph list() list for i in range(N):
  x = list(map(int, input().split()))
  graph.append(x[2:]) i range(N) range N x = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split graph.append(x[2:]) graph.append graph append x[2:] x 2: 2 start = [0] * N start [0] * N [0] 0 N end = [0] * N end [0] * N [0] 0 N visited = [False] * N visited [False] * N [False] False N time = 0 time 0 def dfs(n):
  if visited[n]:
    return
  visited[n] = True
  global time
  time += 1
  start[n] = time
  for i in graph[n]:
    dfs(i-1)
  time += 1
  end[n] = time dfs if visited[n]:
    return
   visited[n] visited n return visited[n] = True visited[n] visited n True global time time += 1 time 1 start[n] = time start[n] start n time for i in graph[n]:
    dfs(i-1)
   i graph[n] graph n dfs(i-1) dfs i-1 i 1 time += 1 time 1 end[n] = time end[n] end n time n n for i in range(N):
  dfs(i) i range(N) range N dfs(i) dfs i for i in range(N):
  print(i+1, start[i], end[i]) i range(N) range N print(i+1, start[i], end[i]) print i+1 i 1 start[i] start i end[i] end i graph = list() list() graph def dfs(n):
  if visited[n]:
    return
  visited[n] = True
  global time
  time += 1
  start[n] = time
  for i in graph[n]:
    dfs(i-1)
  time += 1
  end[n] = time def dfs(n):
  if visited[n]:
    return
  visited[n] = True
  global time
  time += 1
  start[n] = time
  for i in graph[n]:
    dfs(i-1)
  time += 1
  end[n] = time dfs start = [0] * N [0] * N start N = int(input()) int(input()) N end = [0] * N [0] * N end visited = [False] * N [False] * N visited x = list(map(int, input().split())) list(map(int, input().split())) x time = 0 0 time
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
graph = list()
for i in range(N):
  x = list(map(int, input().split()))
  graph.append(x[2:])

start = [0] * N
end = [0] * N
visited = [False] * N
time = 0
def dfs(n):
  if visited[n]:
    return
  visited[n] = True
  global time
  time += 1
  start[n] = time
  for i in graph[n]:
    dfs(i-1)
  time += 1
  end[n] = time

for i in range(N):
  dfs(i)
for i in range(N):
  print(i+1, start[i], end[i])
