N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
    t = list(map(int, input().split()))
    for j in range(t[1]):
        edge[t[0]].append(t[j+2])

#print(1)
def dfs(v, t):
    if d[v] == 0:
        d[v] = t
        t += 1
    else:
        return t
    for nv in edge[v]:
        t = dfs(nv, t)
    if f[v] == 0:
        f[v] = t
        t += 1
    return t

t = 1
for i in range(1,1+N):
    if d[i] == 0:
        t = dfs(i, t)
for i in range(1,1+N):
    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)] 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 for i in range(N):
    t = list(map(int, input().split()))
    for j in range(t[1]):
        edge[t[0]].append(t[j+2])

#print(1) i range(N) range N t = list(map(int, input().split())) t list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for j in range(t[1]):
        edge[t[0]].append(t[j+2])

#print(1) j range(t[1]) range t[1] t 1 edge[t[0]].append(t[j+2]) [t[0]].append [t[0]] edge t[0] t 0 append t[j+2] t j+2 j 2 def dfs(v, t):
    if d[v] == 0:
        d[v] = t
        t += 1
    else:
        return t
    for nv in edge[v]:
        t = dfs(nv, t)
    if f[v] == 0:
        f[v] = t
        t += 1
    return t dfs if d[v] == 0:
        d[v] = t
        t += 1
    else:
        return t
     d[v] == 0 d[v] d v 0 d[v] = t d[v] d v t t += 1 t 1 return t t for nv in edge[v]:
        t = dfs(nv, t)
     nv edge[v] edge v t = dfs(nv, t) t dfs(nv, t) dfs nv t if f[v] == 0:
        f[v] = t
        t += 1
     f[v] == 0 f[v] f v 0 f[v] = t f[v] f v t t += 1 t 1 return t t v v t t t = 1 t 1 for i in range(1,1+N):
    if d[i] == 0:
        t = dfs(i, t) i range(1,1+N) range 1 1+N 1 N if d[i] == 0:
        t = dfs(i, t) d[i] == 0 d[i] d i 0 t = dfs(i, t) t dfs(i, t) dfs i t for i in range(1,1+N):
    print(i, d[i], f[i]) i range(1,1+N) range 1 1+N 1 N print(i, d[i], f[i]) print i d[i] d i f[i] f i t = list(map(int, input().split())) list(map(int, input().split())) t N = int(input()) int(input()) N f = [0] * (N+1) [0] * (N+1) f t = dfs(i, t) dfs(i, t) t edge = [[] for _ in range(N+1)] [[] for _ in range(N+1)] edge t = 1 1 t d = [0] * (N+1) [0] * (N+1) d def dfs(v, t):
    if d[v] == 0:
        d[v] = t
        t += 1
    else:
        return t
    for nv in edge[v]:
        t = dfs(nv, t)
    if f[v] == 0:
        f[v] = t
        t += 1
    return t def dfs(v, t):
    if d[v] == 0:
        d[v] = t
        t += 1
    else:
        return t
    for nv in edge[v]:
        t = dfs(nv, t)
    if f[v] == 0:
        f[v] = t
        t += 1
    return t dfs
N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
    t = list(map(int, input().split()))
    for j in range(t[1]):
        edge[t[0]].append(t[j+2])

#print(1)
def dfs(v, t):
    if d[v] == 0:
        d[v] = t
        t += 1
    else:
        return t
    for nv in edge[v]:
        t = dfs(nv, t)
    if f[v] == 0:
        f[v] = t
        t += 1
    return t

t = 1
for i in range(1,1+N):
    if d[i] == 0:
        t = dfs(i, t)
for i in range(1,1+N):
    print(i, d[i], f[i])

