t = 1
v, d, f = {}, {}, {}

def dfs(i):
  global t, v, d, f
  if i in d:
    return
  if i != 0:
    d[i] = t
    t += 1
  for j in v[i]:
    dfs(j)
  if i != 0:
    f[i] = t
    t += 1

n = int(input())
v[0] = list(range(1, n+1))
for i in range(n):
  tmp = list(map(int, input().split()))
  v[tmp[0]] = tmp[2:]
  v[tmp[0]].sort()
dfs(0)
for i in range(n):
  print("{} {} {}".format(i+1, d[i+1], f[i+1]))
 t = 1 t 1 v, d, f = {}, {}, {} v {} d {} f {} def dfs(i):
  global t, v, d, f
  if i in d:
    return
  if i != 0:
    d[i] = t
    t += 1
  for j in v[i]:
    dfs(j)
  if i != 0:
    f[i] = t
    t += 1 dfs global t, v, d, f if i in d:
    return
   i in d i d return if i != 0:
    d[i] = t
    t += 1
   i != 0 i 0 d[i] = t d[i] d i t t += 1 t 1 for j in v[i]:
    dfs(j)
   j v[i] v i dfs(j) dfs j if i != 0:
    f[i] = t
    t += 1 i != 0 i 0 f[i] = t f[i] f i t t += 1 t 1 i i n = int(input()) n int(input()) int input() input v[0] = list(range(1, n+1)) v[0] v 0 list(range(1, n+1)) list range(1, n+1) range 1 n+1 n 1 for i in range(n):
  tmp = list(map(int, input().split()))
  v[tmp[0]] = tmp[2:]
  v[tmp[0]].sort() i range(n) range n tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v[tmp[0]] = tmp[2:] v[tmp[0]] v tmp[0] tmp 0 tmp[2:] tmp 2: 2 v[tmp[0]].sort() [tmp[0]].sort [tmp[0]] v tmp[0] tmp 0 sort dfs(0) dfs 0 for i in range(n):
  print("{} {} {}".format(i+1, d[i+1], f[i+1])) i range(n) range n print("{} {} {}".format(i+1, d[i+1], f[i+1])) print "{} {} {}".format(i+1, d[i+1], f[i+1]) "{} {} {}".format "{} {} {}" format i+1 i 1 d[i+1] d i+1 i 1 f[i+1] f i+1 i 1 def dfs(i):
  global t, v, d, f
  if i in d:
    return
  if i != 0:
    d[i] = t
    t += 1
  for j in v[i]:
    dfs(j)
  if i != 0:
    f[i] = t
    t += 1 def dfs(i):
  global t, v, d, f
  if i in d:
    return
  if i != 0:
    d[i] = t
    t += 1
  for j in v[i]:
    dfs(j)
  if i != 0:
    f[i] = t
    t += 1 dfs n = int(input()) int(input()) n d, f = {}, {}, {} {} d tmp = list(map(int, input().split())) list(map(int, input().split())) tmp t = 1 1 t f = {}, {}, {} {} f v, d, f = {}, {}, {} {} v
t = 1
v, d, f = {}, {}, {}

def dfs(i):
  global t, v, d, f
  if i in d:
    return
  if i != 0:
    d[i] = t
    t += 1
  for j in v[i]:
    dfs(j)
  if i != 0:
    f[i] = t
    t += 1

n = int(input())
v[0] = list(range(1, n+1))
for i in range(n):
  tmp = list(map(int, input().split()))
  v[tmp[0]] = tmp[2:]
  v[tmp[0]].sort()
dfs(0)
for i in range(n):
  print("{} {} {}".format(i+1, d[i+1], f[i+1]))

