from collections import deque
n = int(input())
graph = [deque([]) for _ in range(n+1)]
ans = [[i, ] for i in range(n+1)]
for i in range(n):
  u, k, *v = list(map(int, input().split()))
  for j in v:
    graph[u].append(j)
stack = deque()
stack.append(1)
marked = []
t = 0
def dfs(v):
  global t
  marked.append(v)
  t += 1
  ans[v].append(t)
  for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
  t += 1
  ans[v].append(t)
for i in range(1, n+1):
  if len(ans[i])==1:
    dfs(i)
for i, x in enumerate(ans):
  if i==0:
    continue
  print(*x) from collections import deque n = int(input()) n int(input()) int input() input deque([]) for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) deque([]) deque [] graph = [deque([]) for _ in range(n+1)] graph [deque([]) for _ in range(n+1)] [i, ] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [i, ] i ans = [[i, ] for i in range(n+1)] ans [[i, ] for i in range(n+1)] for i in range(n):
  u, k, *v = list(map(int, input().split()))
  for j in v:
    graph[u].append(j) i range(n) range n u, k, *v = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *v v for j in v:
    graph[u].append(j) j v graph[u].append(j) [u].append [u] graph u append j stack = deque() stack deque() deque stack.append(1) stack.append stack append 1 marked = [] marked [] t = 0 t 0 def dfs(v):
  global t
  marked.append(v)
  t += 1
  ans[v].append(t)
  for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
  t += 1
  ans[v].append(t) dfs global t marked.append(v) marked.append marked append v t += 1 t 1 ans[v].append(t) [v].append [v] ans v append t for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
   i graph[v] graph v if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
   i in marked i marked continue marked.append(i) marked.append marked append i dfs(i) dfs i t += 1 t 1 ans[v].append(t) [v].append [v] ans v append t v v for i in range(1, n+1):
  if len(ans[i])==1:
    dfs(i) i range(1, n+1) range 1 n+1 n 1 if len(ans[i])==1:
    dfs(i) len(ans[i])==1 len(ans[i]) len ans[i] ans i 1 dfs(i) dfs i for i, x in enumerate(ans):
  if i==0:
    continue
  print(*x) i x enumerate(ans) enumerate ans if i==0:
    continue
   i==0 i 0 continue print(*x) print *x x def dfs(v):
  global t
  marked.append(v)
  t += 1
  ans[v].append(t)
  for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
  t += 1
  ans[v].append(t) def dfs(v):
  global t
  marked.append(v)
  t += 1
  ans[v].append(t)
  for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
  t += 1
  ans[v].append(t) dfs graph = [deque([]) for _ in range(n+1)] [deque([]) for _ in range(n+1)] graph k, *v = list(map(int, input().split())) list(map(int, input().split())) k marked = [] [] marked u, k, *v = list(map(int, input().split())) list(map(int, input().split())) u n = int(input()) int(input()) n stack = deque() deque() stack ans = [[i, ] for i in range(n+1)] [[i, ] for i in range(n+1)] ans t = 0 0 t
from collections import deque
n = int(input())
graph = [deque([]) for _ in range(n+1)]
ans = [[i, ] for i in range(n+1)]
for i in range(n):
  u, k, *v = list(map(int, input().split()))
  for j in v:
    graph[u].append(j)
stack = deque()
stack.append(1)
marked = []
t = 0
def dfs(v):
  global t
  marked.append(v)
  t += 1
  ans[v].append(t)
  for i in graph[v]:
    if i in marked:
      continue
    else:
      marked.append(i)
      dfs(i)
  t += 1
  ans[v].append(t)
for i in range(1, n+1):
  if len(ans[i])==1:
    dfs(i)
for i, x in enumerate(ans):
  if i==0:
    continue
  print(*x)
