import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
g = []
for i in range(n):
    t = na()
    u = t[0] - 1
    k = t[1]
    v = [x-1 for x in t[2:]]
    g.append(v)
d = [0] * n
f = [0] * n
#print(g)
seen = [False] * n
s = 0
t = 0
def dfs(g, v):
    global t
    #print(v+1, t)
    if seen[v]:
        return
    seen[v] = True
    d[v] = t
    t += 1    
    for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
    f[v] = t
    t += 1
for i in range(n):
    if len(g[i]) != 0:
        dfs(g, i)
for i in range(n):
    print(i+1, d[i]+1, f[i]+1)

 import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time math string itertools fractions heapq collections re array bisect sys random time sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf = 10**20 inf 10**20 10 20 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 stdin = sys.stdin stdin sys.stdin sys stdin ni = lambda: int(ns()) ni lambda: int(ns()) int(ns()) int ns() ns na = lambda: list(map(int, stdin.readline().split())) na lambda: list(map(int, stdin.readline().split())) list(map(int, stdin.readline().split())) list map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split ns = lambda: stdin.readline().rstrip() ns lambda: stdin.readline().rstrip() stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip n = ni() n ni() ni g = [] g [] for i in range(n):
    t = na()
    u = t[0] - 1
    k = t[1]
    v = [x-1 for x in t[2:]]
    g.append(v) i range(n) range n t = na() t na() na u = t[0] - 1 u t[0] - 1 t[0] t 0 1 k = t[1] k t[1] t 1 x-1 for x in t[2:] for x in t[2:] x t[2:] t 2: 2 for x in t[2:] x-1 x 1 v = [x-1 for x in t[2:]] v [x-1 for x in t[2:]] g.append(v) g.append g append v d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n seen = [False] * n seen [False] * n [False] False n s = 0 s 0 t = 0 t 0 def dfs(g, v):
    global t
    #print(v+1, t)
    if seen[v]:
        return
    seen[v] = True
    d[v] = t
    t += 1    
    for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
    f[v] = t
    t += 1 dfs global t if seen[v]:
        return
     seen[v] seen v return seen[v] = True seen[v] seen v True d[v] = t d[v] d v t t += 1 t 1 for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
     next_v g[v] g v dfs(g, next_v) dfs g next_v f[v] = t f[v] f v t t += 1 t 1 g g v v for i in range(n):
    if len(g[i]) != 0:
        dfs(g, i) i range(n) range n if len(g[i]) != 0:
        dfs(g, i) len(g[i]) != 0 len(g[i]) len g[i] g i 0 dfs(g, i) dfs g i for i in range(n):
    print(i+1, d[i]+1, f[i]+1) i range(n) range n print(i+1, d[i]+1, f[i]+1) print i+1 i 1 d[i]+1 d[i] d i 1 f[i]+1 f[i] f i 1 s = 0 0 s n = ni() ni() n f = [0] * n [0] * n f na = lambda: list(map(int, stdin.readline().split())) lambda: list(map(int, stdin.readline().split())) na u = t[0] - 1 t[0] - 1 u def dfs(g, v):
    global t
    #print(v+1, t)
    if seen[v]:
        return
    seen[v] = True
    d[v] = t
    t += 1    
    for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
    f[v] = t
    t += 1 def dfs(g, v):
    global t
    #print(v+1, t)
    if seen[v]:
        return
    seen[v] = True
    d[v] = t
    t += 1    
    for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
    f[v] = t
    t += 1 dfs inf = 10**20 10**20 inf stdin = sys.stdin sys.stdin stdin t = na() na() t t = 0 0 t mod = 10**9 + 7 10**9 + 7 mod ns = lambda: stdin.readline().rstrip() lambda: stdin.readline().rstrip() ns seen = [False] * n [False] * n seen ni = lambda: int(ns()) lambda: int(ns()) ni d = [0] * n [0] * n d k = t[1] t[1] k g = [] [] g v = [x-1 for x in t[2:]] [x-1 for x in t[2:]] v
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
g = []
for i in range(n):
    t = na()
    u = t[0] - 1
    k = t[1]
    v = [x-1 for x in t[2:]]
    g.append(v)
d = [0] * n
f = [0] * n
#print(g)
seen = [False] * n
s = 0
t = 0
def dfs(g, v):
    global t
    #print(v+1, t)
    if seen[v]:
        return
    seen[v] = True
    d[v] = t
    t += 1    
    for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
    f[v] = t
    t += 1
for i in range(n):
    if len(g[i]) != 0:
        dfs(g, i)
for i in range(n):
    print(i+1, d[i]+1, f[i]+1)


