def dfs(adj, s, d, f, now):
    now += 1
    d[s] = now
    for t in adj[s]:
        if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
    now += 1
    f[s] = now
    return d, f, now


n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1].append(v - 1)
    adj[u - 1].sort()

d = [-1 for _ in range(n)]
f = [-1 for _ in range(n)]
now = 0
for s in range(n):
    if f[s] < 0:
        d, f, now = dfs(adj, s, d, f, now)

for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) def dfs(adj, s, d, f, now):
    now += 1
    d[s] = now
    for t in adj[s]:
        if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
    now += 1
    f[s] = now
    return d, f, now dfs now += 1 now 1 d[s] = now d[s] d s now for t in adj[s]:
        if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
     t adj[s] adj s if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
     t != s and f[t] < 0 and d[t] < 0 t != s and f[t] < 0 t != s t s f[t] < 0 f[t] f t 0 d[t] < 0 d[t] d t 0 d, f, now = dfs(adj, t, d, f, now) d dfs(adj, t, d, f, now) dfs adj t d f now f now now += 1 now 1 f[s] = now f[s] f s now return d, f, now return d, f, now d f now adj adj s s d d f f now now n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] adj = [[] for _ in range(n)] adj [[] for _ in range(n)] for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1].append(v - 1)
    adj[u - 1].sort() _ range(n) range n int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x s = [int(x) for x in input().split()] s [int(x) for x in input().split()] u = s[0] u s[0] s 0 for v in s[2:]:
        adj[u - 1].append(v - 1)
     v s[2:] s 2: 2 adj[u - 1].append(v - 1) [u - 1].append [u - 1] adj u - 1 u 1 append v - 1 v 1 adj[u - 1].sort() [u - 1].sort [u - 1] adj u - 1 u 1 sort -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 d = [-1 for _ in range(n)] d [-1 for _ in range(n)] -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 f = [-1 for _ in range(n)] f [-1 for _ in range(n)] now = 0 now 0 for s in range(n):
    if f[s] < 0:
        d, f, now = dfs(adj, s, d, f, now) s range(n) range n if f[s] < 0:
        d, f, now = dfs(adj, s, d, f, now) f[s] < 0 f[s] f s 0 d, f, now = dfs(adj, s, d, f, now) d dfs(adj, s, d, f, now) dfs adj s d f now f now for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) i range(n) range n print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) print str(i + 1) + " " + str(d[i]) + " " + str(f[i]) str(i + 1) + " " + str(d[i]) + " " str(i + 1) + " " + str(d[i]) str(i + 1) + " " str(i + 1) str i + 1 i 1 " " str(d[i]) str d[i] d i " " str(f[i]) str f[i] f i now = dfs(adj, s, d, f, now) dfs(adj, s, d, f, now) now n = int(input()) int(input()) n d, f, now = dfs(adj, s, d, f, now) dfs(adj, s, d, f, now) d u = s[0] s[0] u f = [-1 for _ in range(n)] [-1 for _ in range(n)] f def dfs(adj, s, d, f, now):
    now += 1
    d[s] = now
    for t in adj[s]:
        if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
    now += 1
    f[s] = now
    return d, f, now def dfs(adj, s, d, f, now):
    now += 1
    d[s] = now
    for t in adj[s]:
        if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
    now += 1
    f[s] = now
    return d, f, now dfs now = 0 0 now adj = [[] for _ in range(n)] [[] for _ in range(n)] adj d = [-1 for _ in range(n)] [-1 for _ in range(n)] d f, now = dfs(adj, s, d, f, now) dfs(adj, s, d, f, now) f s = [int(x) for x in input().split()] [int(x) for x in input().split()] s
def dfs(adj, s, d, f, now):
    now += 1
    d[s] = now
    for t in adj[s]:
        if t != s and f[t] < 0 and d[t] < 0:
            d, f, now = dfs(adj, t, d, f, now)
    now += 1
    f[s] = now
    return d, f, now


n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1].append(v - 1)
    adj[u - 1].sort()

d = [-1 for _ in range(n)]
f = [-1 for _ in range(n)]
now = 0
for s in range(n):
    if f[s] < 0:
        d, f, now = dfs(adj, s, d, f, now)

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