from enum import Enum

class Color(Enum):
  WHITE = 0
  GRAY = 1
  BLACK = 2

def dfs_visit(u, total_time):
  colors[u] = Color.GRAY
  total_time += 1
  d[u] = total_time
  stack.append(u)
  for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
  colors[u] = Color.BLACK
  total_time += 1
  f[u] = total_time
  return total_time



def dfs(total_time):
  for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time)

N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1

colors = [Color.WHITE for i in range(N)]
stack = []
total_time = 0
d = [0 for i in range(N)]
f = [0 for i in range(N)]

dfs(total_time)

for i in range(N):
  print(i+1, d[i], f[i])
 from enum import Enum class Color(Enum):
  WHITE = 0
  GRAY = 1
  BLACK = 2 Color WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 Enum def dfs_visit(u, total_time):
  colors[u] = Color.GRAY
  total_time += 1
  d[u] = total_time
  stack.append(u)
  for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
  colors[u] = Color.BLACK
  total_time += 1
  f[u] = total_time
  return total_time dfs_visit colors[u] = Color.GRAY colors[u] colors u Color.GRAY Color GRAY total_time += 1 total_time 1 d[u] = total_time d[u] d u total_time stack.append(u) stack.append stack append u for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
   v range(N) range N if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
   adj[u][v] == 1 and colors[v] == Color.WHITE adj[u][v] == 1 adj[u][v] [u] adj u v 1 colors[v] == Color.WHITE colors[v] colors v Color.WHITE Color WHITE total_time = dfs_visit(v, total_time) total_time dfs_visit(v, total_time) dfs_visit v total_time colors[u] = Color.BLACK colors[u] colors u Color.BLACK Color BLACK total_time += 1 total_time 1 f[u] = total_time f[u] f u total_time return total_time total_time u u total_time total_time def dfs(total_time):
  for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time) dfs for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time) i range(N) range N if colors[i] != Color.WHITE:
      continue
     colors[i] != Color.WHITE colors[i] colors i Color.WHITE Color WHITE continue total_time = dfs_visit(i, total_time) total_time dfs_visit(i, total_time) dfs_visit i total_time total_time total_time N = int(input()) N int(input()) int input() input list(map(int, input().split())) for i in range(N) for i in range(N) i range(N) range N for i in range(N) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split L = [list(map(int, input().split())) for i in range(N)] L [list(map(int, input().split())) for i in range(N)] [0 for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(N)] adj = [[0 for i in range(N)] for j in range(N)] adj [[0 for i in range(N)] for j in range(N)] for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1 i range(N) range N for node in L[i][2:]:
    adj[i][node-1] = 1 node L[i][2:] [i] L i 2: 2 adj[i][node-1] = 1 adj[i][node-1] [i] adj i node-1 node 1 1 Color.WHITE for i in range(N) for i in range(N) i range(N) range N for i in range(N) Color.WHITE Color WHITE colors = [Color.WHITE for i in range(N)] colors [Color.WHITE for i in range(N)] stack = [] stack [] total_time = 0 total_time 0 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)] dfs(total_time) dfs total_time for i in range(N):
  print(i+1, d[i], f[i]) i range(N) range N print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i adj = [[0 for i in range(N)] for j in range(N)] [[0 for i in range(N)] for j in range(N)] adj def dfs_visit(u, total_time):
  colors[u] = Color.GRAY
  total_time += 1
  d[u] = total_time
  stack.append(u)
  for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
  colors[u] = Color.BLACK
  total_time += 1
  f[u] = total_time
  return total_time def dfs_visit(u, total_time):
  colors[u] = Color.GRAY
  total_time += 1
  d[u] = total_time
  stack.append(u)
  for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
  colors[u] = Color.BLACK
  total_time += 1
  f[u] = total_time
  return total_time dfs_visit colors = [Color.WHITE for i in range(N)] [Color.WHITE for i in range(N)] colors L = [list(map(int, input().split())) for i in range(N)] [list(map(int, input().split())) for i in range(N)] L stack = [] [] stack d = [0 for i in range(N)] [0 for i in range(N)] d class Color(Enum):
  WHITE = 0
  GRAY = 1
  BLACK = 2 class Color(Enum):
  WHITE = 0
  GRAY = 1
  BLACK = 2 Color total_time = 0 0 total_time N = int(input()) int(input()) N def dfs(total_time):
  for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time) def dfs(total_time):
  for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time) dfs f = [0 for i in range(N)] [0 for i in range(N)] f
from enum import Enum

class Color(Enum):
  WHITE = 0
  GRAY = 1
  BLACK = 2

def dfs_visit(u, total_time):
  colors[u] = Color.GRAY
  total_time += 1
  d[u] = total_time
  stack.append(u)
  for v in range(N):
    if adj[u][v] == 1 and colors[v] == Color.WHITE:
      total_time = dfs_visit(v, total_time)
  colors[u] = Color.BLACK
  total_time += 1
  f[u] = total_time
  return total_time



def dfs(total_time):
  for i in range(N):
    if colors[i] != Color.WHITE:
      continue
    total_time = dfs_visit(i, total_time)

N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1

colors = [Color.WHITE for i in range(N)]
stack = []
total_time = 0
d = [0 for i in range(N)]
f = [0 for i in range(N)]

dfs(total_time)

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

