n = int(input())
graph = {}
for _ in range(n):
  i = list(map(int,input().split()))
  graph[i[0]] = i[2:]

first = {i:0 for i in range(1,n+1)}
last = {i:0 for i in range(1,n+1)}
seen = set()
time = 1

def dfs(v):
  global time
  seen.add(v)
  first[v] = time
  time += 1
  for nxt in graph[v]:
    if nxt in seen:
      continue
    dfs(nxt)
  last[v] = time
  time += 1

for i in range(1,n+1):
  if i not in seen:
    dfs(i)
  
for i in range(1,n+1):
  print(i, first[i], last[i])

 n = int(input()) n int(input()) int input() input graph = {} graph {} for _ in range(n):
  i = list(map(int,input().split()))
  graph[i[0]] = i[2:] _ range(n) range n i = list(map(int,input().split())) i list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split graph[i[0]] = i[2:] graph[i[0]] graph i[0] i 0 i[2:] i 2: 2 i:0 for i in range(1,n+1) for i in range(1,n+1) i range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1) i 0 first = {i:0 for i in range(1,n+1)} first {i:0 for i in range(1,n+1)} i:0 for i in range(1,n+1) for i in range(1,n+1) i range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1) i 0 last = {i:0 for i in range(1,n+1)} last {i:0 for i in range(1,n+1)} seen = set() seen set() set time = 1 time 1 def dfs(v):
  global time
  seen.add(v)
  first[v] = time
  time += 1
  for nxt in graph[v]:
    if nxt in seen:
      continue
    dfs(nxt)
  last[v] = time
  time += 1 dfs global time seen.add(v) seen.add seen add v first[v] = time first[v] first v time time += 1 time 1 for nxt in graph[v]:
    if nxt in seen:
      continue
    dfs(nxt)
   nxt graph[v] graph v if nxt in seen:
      continue
     nxt in seen nxt seen continue dfs(nxt) dfs nxt last[v] = time last[v] last v time time += 1 time 1 v v for i in range(1,n+1):
  if i not in seen:
    dfs(i)
   i range(1,n+1) range 1 n+1 n 1 if i not in seen:
    dfs(i)
   i not in seen i seen dfs(i) dfs i for i in range(1,n+1):
  print(i, first[i], last[i]) i range(1,n+1) range 1 n+1 n 1 print(i, first[i], last[i]) print i first[i] first i last[i] last i n = int(input()) int(input()) n i = list(map(int,input().split())) list(map(int,input().split())) i time = 1 1 time def dfs(v):
  global time
  seen.add(v)
  first[v] = time
  time += 1
  for nxt in graph[v]:
    if nxt in seen:
      continue
    dfs(nxt)
  last[v] = time
  time += 1 def dfs(v):
  global time
  seen.add(v)
  first[v] = time
  time += 1
  for nxt in graph[v]:
    if nxt in seen:
      continue
    dfs(nxt)
  last[v] = time
  time += 1 dfs first = {i:0 for i in range(1,n+1)} {i:0 for i in range(1,n+1)} first graph = {} {} graph last = {i:0 for i in range(1,n+1)} {i:0 for i in range(1,n+1)} last seen = set() set() seen
n = int(input())
graph = {}
for _ in range(n):
  i = list(map(int,input().split()))
  graph[i[0]] = i[2:]

first = {i:0 for i in range(1,n+1)}
last = {i:0 for i in range(1,n+1)}
seen = set()
time = 1

def dfs(v):
  global time
  seen.add(v)
  first[v] = time
  time += 1
  for nxt in graph[v]:
    if nxt in seen:
      continue
    dfs(nxt)
  last[v] = time
  time += 1

for i in range(1,n+1):
  if i not in seen:
    dfs(i)
  
for i in range(1,n+1):
  print(i, first[i], last[i])


