from collections import defaultdict


def dfs(v, t):
    if start[v] == 0:
        start[v] = t
        t += 1
    else:
        return t

    for nv in graph[v]:
        t = dfs(nv, t)

    end[v] = t
    t += 1

    return t


n = int(input())

graph = defaultdict(list)

for _ in range(n):
    u, k, *v = map(int, input().split())
    for v in v:
        graph[u].append(v)

start = [0] * (n + 1)
end = [0] * (n + 1)


t = 1

for i in range(1, n + 1):
    t = dfs(i, t)

for i in range(1, n + 1):
    print(i, start[i], end[i]) from collections import defaultdict def dfs(v, t):
    if start[v] == 0:
        start[v] = t
        t += 1
    else:
        return t

    for nv in graph[v]:
        t = dfs(nv, t)

    end[v] = t
    t += 1

    return t dfs if start[v] == 0:
        start[v] = t
        t += 1
    else:
        return t

     start[v] == 0 start[v] start v 0 start[v] = t start[v] start v t t += 1 t 1 return t t for nv in graph[v]:
        t = dfs(nv, t)

     nv graph[v] graph v t = dfs(nv, t) t dfs(nv, t) dfs nv t end[v] = t end[v] end v t t += 1 t 1 return t t v v t t n = int(input()) n int(input()) int input() input graph = defaultdict(list) graph defaultdict(list) defaultdict list for _ in range(n):
    u, k, *v = map(int, input().split())
    for v in v:
        graph[u].append(v) _ range(n) range n u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v for v in v:
        graph[u].append(v) v v graph[u].append(v) [u].append [u] graph u append v start = [0] * (n + 1) start [0] * (n + 1) [0] 0 n + 1 n 1 end = [0] * (n + 1) end [0] * (n + 1) [0] 0 n + 1 n 1 t = 1 t 1 for i in range(1, n + 1):
    t = dfs(i, t) i range(1, n + 1) range 1 n + 1 n 1 t = dfs(i, t) t dfs(i, t) dfs i t for i in range(1, n + 1):
    print(i, start[i], end[i]) i range(1, n + 1) range 1 n + 1 n 1 print(i, start[i], end[i]) print i start[i] start i end[i] end i def dfs(v, t):
    if start[v] == 0:
        start[v] = t
        t += 1
    else:
        return t

    for nv in graph[v]:
        t = dfs(nv, t)

    end[v] = t
    t += 1

    return t def dfs(v, t):
    if start[v] == 0:
        start[v] = t
        t += 1
    else:
        return t

    for nv in graph[v]:
        t = dfs(nv, t)

    end[v] = t
    t += 1

    return t dfs n = int(input()) int(input()) n end = [0] * (n + 1) [0] * (n + 1) end u, k, *v = map(int, input().split()) map(int, input().split()) u start = [0] * (n + 1) [0] * (n + 1) start t = dfs(i, t) dfs(i, t) t graph = defaultdict(list) defaultdict(list) graph k, *v = map(int, input().split()) map(int, input().split()) k t = 1 1 t
from collections import defaultdict


def dfs(v, t):
    if start[v] == 0:
        start[v] = t
        t += 1
    else:
        return t

    for nv in graph[v]:
        t = dfs(nv, t)

    end[v] = t
    t += 1

    return t


n = int(input())

graph = defaultdict(list)

for _ in range(n):
    u, k, *v = map(int, input().split())
    for v in v:
        graph[u].append(v)

start = [0] * (n + 1)
end = [0] * (n + 1)


t = 1

for i in range(1, n + 1):
    t = dfs(i, t)

for i in range(1, n + 1):
    print(i, start[i], end[i])
