def visit(u):
  global t
  flag[u] = 1
  t += 1
  s[u] = t
  for v in range(n):
    if M[u][v]==0:
      continue
    if flag[v]==0:
      visit(v)
  flag[u] = 2
  t += 1
  e[u] = t


def dfs():
  for u in range(n):
    if flag[u]==0:
      visit(u)
  for u in range(n):
    print '%d %d %d' % (u+1, s[u], e[u])


n = input()
t = 0
flag = [0 for row in range(n)]
s = [0 for row in range(n)]
e = [0 for row in range(n)]
M = [[0 for col in range(n)] for row in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  a = str[2:]
  u -= 1
  for v in a:
    M[u][v-1] = 1

dfs() def visit(u):
  global t
  flag[u] = 1
  t += 1
  s[u] = t
  for v in range(n):
    if M[u][v]==0:
      continue
    if flag[v]==0:
      visit(v)
  flag[u] = 2
  t += 1
  e[u] = t visit global t flag[u] = 1 flag[u] flag u 1 t += 1 t 1 s[u] = t s[u] s u t for v in range(n):
    if M[u][v]==0:
      continue
    if flag[v]==0:
      visit(v)
   v range(n) range n if M[u][v]==0:
      continue
     M[u][v]==0 M[u][v] [u] M u v 0 continue if flag[v]==0:
      visit(v)
   flag[v]==0 flag[v] flag v 0 visit(v) visit v flag[u] = 2 flag[u] flag u 2 t += 1 t 1 e[u] = t e[u] e u t u u def dfs():
  for u in range(n):
    if flag[u]==0:
      visit(u)
  for u in range(n):
    print '%d %d %d' % (u+1, s[u], e[u]) dfs for u in range(n):
    if flag[u]==0:
      visit(u)
   u range(n) range n if flag[u]==0:
      visit(u)
   flag[u]==0 flag[u] flag u 0 visit(u) visit u for u in range(n):
    print '%d %d %d' % (u+1, s[u], e[u]) u range(n) range n print '%d %d %d' % (u+1, s[u], e[u]) '%d %d %d' (u+1, s[u], e[u]) u+1 u 1 s[u] s u e[u] e u n = input() n input() input t = 0 t 0 0 for row in range(n) for row in range(n) row range(n) range n for row in range(n) 0 flag = [0 for row in range(n)] flag [0 for row in range(n)] 0 for row in range(n) for row in range(n) row range(n) range n for row in range(n) 0 s = [0 for row in range(n)] s [0 for row in range(n)] 0 for row in range(n) for row in range(n) row range(n) range n for row in range(n) 0 e = [0 for row in range(n)] e [0 for row in range(n)] [0 for col in range(n)] for row in range(n) for row in range(n) row range(n) range n for row in range(n) [0 for col in range(n)] M = [[0 for col in range(n)] for row in range(n)] M [[0 for col in range(n)] for row in range(n)] for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  a = str[2:]
  u -= 1
  for v in a:
    M[u][v-1] = 1 i range(n) range n str = map(int, raw_input().split()) str map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split u = str[0] u str[0] str 0 k = str[1] k str[1] str 1 a = str[2:] a str[2:] str 2: 2 u -= 1 u 1 for v in a:
    M[u][v-1] = 1 v a M[u][v-1] = 1 M[u][v-1] [u] M u v-1 v 1 1 dfs() dfs str = map(int, raw_input().split()) map(int, raw_input().split()) str def dfs():
  for u in range(n):
    if flag[u]==0:
      visit(u)
  for u in range(n):
    print '%d %d %d' % (u+1, s[u], e[u]) def dfs():
  for u in range(n):
    if flag[u]==0:
      visit(u)
  for u in range(n):
    print '%d %d %d' % (u+1, s[u], e[u]) dfs k = str[1] str[1] k def visit(u):
  global t
  flag[u] = 1
  t += 1
  s[u] = t
  for v in range(n):
    if M[u][v]==0:
      continue
    if flag[v]==0:
      visit(v)
  flag[u] = 2
  t += 1
  e[u] = t def visit(u):
  global t
  flag[u] = 1
  t += 1
  s[u] = t
  for v in range(n):
    if M[u][v]==0:
      continue
    if flag[v]==0:
      visit(v)
  flag[u] = 2
  t += 1
  e[u] = t visit flag = [0 for row in range(n)] [0 for row in range(n)] flag n = input() input() n u = str[0] str[0] u t = 0 0 t s = [0 for row in range(n)] [0 for row in range(n)] s a = str[2:] str[2:] a e = [0 for row in range(n)] [0 for row in range(n)] e M = [[0 for col in range(n)] for row in range(n)] [[0 for col in range(n)] for row in range(n)] M u -= 1 1 u
def visit(u):
  global t
  flag[u] = 1
  t += 1
  s[u] = t
  for v in range(n):
    if M[u][v]==0:
      continue
    if flag[v]==0:
      visit(v)
  flag[u] = 2
  t += 1
  e[u] = t


def dfs():
  for u in range(n):
    if flag[u]==0:
      visit(u)
  for u in range(n):
    print '%d %d %d' % (u+1, s[u], e[u])


n = input()
t = 0
flag = [0 for row in range(n)]
s = [0 for row in range(n)]
e = [0 for row in range(n)]
M = [[0 for col in range(n)] for row in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  a = str[2:]
  u -= 1
  for v in a:
    M[u][v-1] = 1

dfs()