#!/usr/bin/env python3
import sys
sys.setrecursionlimit(15000)
n = int(sys.stdin.readline())

ret = []
inp = sys.stdin.readlines()
G = [None]*(n)
d = [0]*(n)
f = [0]*(n)
def dfs(i,t):
  if d[i] != 0:
    return t
  t = t+1
  d[i] = t
  for j in G[i]:
    t = dfs(j,t)
  f[i] = t+1
  return f[i]
for i in range(n):
  v = list(map(int,inp[i].split()))
  G[v[0]-1] = list(map(lambda x: int(x-1),v[2:]))
#print(G)
t = 0
for j in range(n):
  t = dfs(j,t)

for i in range(n):
  print(i+1,d[i],f[i]) import sys sys sys.setrecursionlimit(15000) sys.setrecursionlimit sys setrecursionlimit 15000 n = int(sys.stdin.readline()) n int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline ret = [] ret [] inp = sys.stdin.readlines() inp sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines G = [None]*(n) G [None]*(n) [None] None n d = [0]*(n) d [0]*(n) [0] 0 n f = [0]*(n) f [0]*(n) [0] 0 n def dfs(i,t):
  if d[i] != 0:
    return t
  t = t+1
  d[i] = t
  for j in G[i]:
    t = dfs(j,t)
  f[i] = t+1
  return f[i] dfs if d[i] != 0:
    return t
   d[i] != 0 d[i] d i 0 return t t t = t+1 t t+1 t 1 d[i] = t d[i] d i t for j in G[i]:
    t = dfs(j,t)
   j G[i] G i t = dfs(j,t) t dfs(j,t) dfs j t f[i] = t+1 f[i] f i t+1 t 1 return f[i] f[i] f i i i t t for i in range(n):
  v = list(map(int,inp[i].split()))
  G[v[0]-1] = list(map(lambda x: int(x-1),v[2:]))
#print(G) i range(n) range n v = list(map(int,inp[i].split())) v list(map(int,inp[i].split())) list map(int,inp[i].split()) map int inp[i].split() [i].split [i] inp i split G[v[0]-1] = list(map(lambda x: int(x-1),v[2:])) G[v[0]-1] G v[0]-1 v[0] v 0 1 list(map(lambda x: int(x-1),v[2:])) list map(lambda x: int(x-1),v[2:]) map lambda x: int(x-1) int(x-1) int x-1 x 1 x v[2:] v 2: 2 t = 0 t 0 for j in range(n):
  t = dfs(j,t) j range(n) range n t = dfs(j,t) t dfs(j,t) dfs j t 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 n = int(sys.stdin.readline()) int(sys.stdin.readline()) n ret = [] [] ret G = [None]*(n) [None]*(n) G v = list(map(int,inp[i].split())) list(map(int,inp[i].split())) v t = 0 0 t t = dfs(j,t) dfs(j,t) t def dfs(i,t):
  if d[i] != 0:
    return t
  t = t+1
  d[i] = t
  for j in G[i]:
    t = dfs(j,t)
  f[i] = t+1
  return f[i] def dfs(i,t):
  if d[i] != 0:
    return t
  t = t+1
  d[i] = t
  for j in G[i]:
    t = dfs(j,t)
  f[i] = t+1
  return f[i] dfs inp = sys.stdin.readlines() sys.stdin.readlines() inp d = [0]*(n) [0]*(n) d f = [0]*(n) [0]*(n) f
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(15000)
n = int(sys.stdin.readline())

ret = []
inp = sys.stdin.readlines()
G = [None]*(n)
d = [0]*(n)
f = [0]*(n)
def dfs(i,t):
  if d[i] != 0:
    return t
  t = t+1
  d[i] = t
  for j in G[i]:
    t = dfs(j,t)
  f[i] = t+1
  return f[i]
for i in range(n):
  v = list(map(int,inp[i].split()))
  G[v[0]-1] = list(map(lambda x: int(x-1),v[2:]))
#print(G)
t = 0
for j in range(n):
  t = dfs(j,t)

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