n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
  v,k,*u=list(map(int,input().split()))
  edge[v]=u
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(now,t):
  d[now]=t
  vis.append(now)
  for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
  f[now]=t+1
  return t+1
vis=[]
t=1
for i in range(1,n+1):
  if i not in vis:
    t=dfs(i,t)+1
for i in range(1,n+1):
  print(i,d[i],f[i]) n=int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] edge=[[] for _ in range(n+1)] edge [[] for _ in range(n+1)] for i in range(n):
  v,k,*u=list(map(int,input().split()))
  edge[v]=u i range(n) range n v,k,*u=list(map(int,input().split())) v list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split k *u u edge[v]=u edge[v] edge v u d=[0]*(n+1) d [0]*(n+1) [0] 0 n+1 n 1 f=[0]*(n+1) f [0]*(n+1) [0] 0 n+1 n 1 def dfs(now,t):
  d[now]=t
  vis.append(now)
  for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
  f[now]=t+1
  return t+1 dfs d[now]=t d[now] d now t vis.append(now) vis.append vis append now for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
   i edge[now] edge now if i not in vis:
      t=dfs(i,t+1)
   i not in vis i vis t=dfs(i,t+1) t dfs(i,t+1) dfs i t+1 t 1 f[now]=t+1 f[now] f now t+1 t 1 return t+1 t+1 t 1 now now t t vis=[] vis [] t=1 t 1 for i in range(1,n+1):
  if i not in vis:
    t=dfs(i,t)+1 i range(1,n+1) range 1 n+1 n 1 if i not in vis:
    t=dfs(i,t)+1 i not in vis i vis t=dfs(i,t)+1 t dfs(i,t)+1 dfs(i,t) dfs i t 1 for i in range(1,n+1):
  print(i,d[i],f[i]) i range(1,n+1) range 1 n+1 n 1 print(i,d[i],f[i]) print i d[i] d i f[i] f i v,k,*u=list(map(int,input().split())) list(map(int,input().split())) v d=[0]*(n+1) [0]*(n+1) d def dfs(now,t):
  d[now]=t
  vis.append(now)
  for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
  f[now]=t+1
  return t+1 def dfs(now,t):
  d[now]=t
  vis.append(now)
  for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
  f[now]=t+1
  return t+1 dfs vis=[] [] vis t=1 1 t k,*u=list(map(int,input().split())) list(map(int,input().split())) k f=[0]*(n+1) [0]*(n+1) f edge=[[] for _ in range(n+1)] [[] for _ in range(n+1)] edge n=int(input()) int(input()) n t=dfs(i,t)+1 dfs(i,t)+1 t
n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
  v,k,*u=list(map(int,input().split()))
  edge[v]=u
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(now,t):
  d[now]=t
  vis.append(now)
  for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
  f[now]=t+1
  return t+1
vis=[]
t=1
for i in range(1,n+1):
  if i not in vis:
    t=dfs(i,t)+1
for i in range(1,n+1):
  print(i,d[i],f[i])
