# N=4
# G=[[2],[4],[],[3]]
import sys
sys.setrecursionlimit(1000000)

N=int(input())
G=[list(map(int, input().split()))[2:] for _ in range(N)]

v=[False]*N
d=[0]*N
f=[0]*N
timecount=1

def dfs(i):
    global timecount
    if v[i] : return
    v[i] = True
    d[i] = timecount
    # print("D",i+1,timecount)
    timecount += 1
    for p in G[i]:
        dfs(p-1)
    # print("F",i+1,timecount)
    f[i] = timecount
    timecount += 1
    return

for i in range(N):
  if v[i]==0: dfs(i)

for i in range(N):
    print(i+1, d[i], f[i]) import sys sys sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 N=int(input()) N int(input()) int input() input list(map(int, input().split()))[2:] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int, input().split()))[2:] (map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 2: 2 G=[list(map(int, input().split()))[2:] for _ in range(N)] G [list(map(int, input().split()))[2:] for _ in range(N)] v=[False]*N v [False]*N [False] False N d=[0]*N d [0]*N [0] 0 N f=[0]*N f [0]*N [0] 0 N timecount=1 timecount 1 def dfs(i):
    global timecount
    if v[i] : return
    v[i] = True
    d[i] = timecount
    # print("D",i+1,timecount)
    timecount += 1
    for p in G[i]:
        dfs(p-1)
    # print("F",i+1,timecount)
    f[i] = timecount
    timecount += 1
    return dfs global timecount if v[i] : return
     v[i] v i v[i] = True v[i] v i True d[i] = timecount d[i] d i timecount timecount += 1 timecount 1 for p in G[i]:
        dfs(p-1)
    # print("F",i+1,timecount)
     p G[i] G i dfs(p-1) dfs p-1 p 1 f[i] = timecount f[i] f i timecount timecount += 1 timecount 1 return i i for i in range(N):
  if v[i]==0: dfs(i) i range(N) range N if v[i]==0: dfs( v[i]==0 v[i] v i 0 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 def dfs(i):
    global timecount
    if v[i] : return
    v[i] = True
    d[i] = timecount
    # print("D",i+1,timecount)
    timecount += 1
    for p in G[i]:
        dfs(p-1)
    # print("F",i+1,timecount)
    f[i] = timecount
    timecount += 1
    return def dfs(i):
    global timecount
    if v[i] : return
    v[i] = True
    d[i] = timecount
    # print("D",i+1,timecount)
    timecount += 1
    for p in G[i]:
        dfs(p-1)
    # print("F",i+1,timecount)
    f[i] = timecount
    timecount += 1
    return dfs f=[0]*N [0]*N f d=[0]*N [0]*N d N=int(input()) int(input()) N v=[False]*N [False]*N v G=[list(map(int, input().split()))[2:] for _ in range(N)] [list(map(int, input().split()))[2:] for _ in range(N)] G timecount=1 1 timecount
# N=4
# G=[[2],[4],[],[3]]
import sys
sys.setrecursionlimit(1000000)

N=int(input())
G=[list(map(int, input().split()))[2:] for _ in range(N)]

v=[False]*N
d=[0]*N
f=[0]*N
timecount=1

def dfs(i):
    global timecount
    if v[i] : return
    v[i] = True
    d[i] = timecount
    # print("D",i+1,timecount)
    timecount += 1
    for p in G[i]:
        dfs(p-1)
    # print("F",i+1,timecount)
    f[i] = timecount
    timecount += 1
    return

for i in range(N):
  if v[i]==0: dfs(i)

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