n = int(input())
link = {}

for i in range(n):
    a = list(map(int, input().split()))
    a.reverse()

    u, k = a.pop(), a.pop()
    link[u] = []
    for j in range(k):
        link[u] += [a.pop()]

d, f = {}, {}
t = 0


def dfs(u):
    global t
    t += 1
    d[u] = t

    for v in link[u]:
        if v not in d: dfs(v)

    if u not in f:
        t += 1
        f[u] = t


for u in range(1, n + 1):
    if u not in d: dfs(u)

for i in range(1, n + 1):
    print(i, d[i], f[i])
 n = int(input()) n int(input()) int input() input link = {} link {} for i in range(n):
    a = list(map(int, input().split()))
    a.reverse()

    u, k = a.pop(), a.pop()
    link[u] = []
    for j in range(k):
        link[u] += [a.pop()] i range(n) range n a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split a.reverse() a.reverse a reverse u, k = a.pop(), a.pop() u a.pop() a.pop a pop k a.pop() a.pop a pop link[u] = [] link[u] link u [] for j in range(k):
        link[u] += [a.pop()] j range(k) range k link[u] += [a.pop()] link[u] link u [a.pop()] a.pop() a.pop a pop d, f = {}, {} d {} f {} t = 0 t 0 def dfs(u):
    global t
    t += 1
    d[u] = t

    for v in link[u]:
        if v not in d: dfs(v)

    if u not in f:
        t += 1
        f[u] = t dfs global t t += 1 t 1 d[u] = t d[u] d u t for v in link[u]:
        if v not in d: dfs(v)

     v link[u] link u if v not in d: dfs(v)

     v not in d v d if u not in f:
        t += 1
        f[u] = t u not in f u f t += 1 t 1 f[u] = t f[u] f u t u u for u in range(1, n + 1):
    if u not in d: dfs(u) u range(1, n + 1) range 1 n + 1 n 1 if u not in d: df u not in d u d for i in range(1, n + 1):
    print(i, d[i], f[i]) i range(1, n + 1) range 1 n + 1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i u, k = a.pop(), a.pop() a.pop() u d, f = {}, {} {} d f = {}, {} {} f def dfs(u):
    global t
    t += 1
    d[u] = t

    for v in link[u]:
        if v not in d: dfs(v)

    if u not in f:
        t += 1
        f[u] = t def dfs(u):
    global t
    t += 1
    d[u] = t

    for v in link[u]:
        if v not in d: dfs(v)

    if u not in f:
        t += 1
        f[u] = t dfs link = {} {} link a = list(map(int, input().split())) list(map(int, input().split())) a t = 0 0 t k = a.pop(), a.pop() a.pop() k n = int(input()) int(input()) n
n = int(input())
link = {}

for i in range(n):
    a = list(map(int, input().split()))
    a.reverse()

    u, k = a.pop(), a.pop()
    link[u] = []
    for j in range(k):
        link[u] += [a.pop()]

d, f = {}, {}
t = 0


def dfs(u):
    global t
    t += 1
    d[u] = t

    for v in link[u]:
        if v not in d: dfs(v)

    if u not in f:
        t += 1
        f[u] = t


for u in range(1, n + 1):
    if u not in d: dfs(u)

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

