# -*- coding: utf_8 -*-

level = False
def debug(v):
    if level:
        print(v)

n = int(input())
a = [0]

for i in range(n):
    v = input().split()
    v.pop(0)
    v.pop(0)
    a.append([int(x) for x in v])

debug(a)
stack = [1]
results = [[0 for i in range(2)] for j in range(n + 1)]
results[0][0] = 0
time = 0

def depth_first_search(a, stack):
    debug(a)
    debug(results)
    debug(stack)
    global time
    if len(stack) == 0:
        return

    v = stack.pop()
    if results[v][0] == 0:
        time += 1
        results[v][0] = time

    es = a[v]
    if len(es) == 0 and results[v][1] == 0:
        time += 1
        results[v][1] = time

    if len(es) != 0:
        stack.append(v)
        next_vert = es.pop(0)
        if results[next_vert][0] == 0:
            stack.append(next_vert)

    depth_first_search(a, stack)

for i in range(n):
    stack = [i + 1]
    depth_first_search(a, stack)

debug(results)

results.pop(0)

i = 1
for row in results:
    print(str(i) + " " + str(row[0]) + " " + str(row[1]))
    i += 1 level = False level False def debug(v):
    if level:
        print(v) debug if level:
        print(v) level print(v) print v v v n = int(input()) n int(input()) int input() input a = [0] a [0] 0 for i in range(n):
    v = input().split()
    v.pop(0)
    v.pop(0)
    a.append([int(x) for x in v]) i range(n) range n v = input().split() v input().split() ().split () input split v.pop(0) v.pop v pop 0 v.pop(0) v.pop v pop 0 int(x) for x in v for x in v x v for x in v int(x) int x a.append([int(x) for x in v]) a.append a append [int(x) for x in v] debug(a) debug a stack = [1] stack [1] 1 [0 for i in range(2)] for j in range(n + 1) for j in range(n + 1) j range(n + 1) range n + 1 n 1 for j in range(n + 1) [0 for i in range(2)] results = [[0 for i in range(2)] for j in range(n + 1)] results [[0 for i in range(2)] for j in range(n + 1)] results[0][0] = 0 results[0][0] [0] results 0 0 0 time = 0 time 0 def depth_first_search(a, stack):
    debug(a)
    debug(results)
    debug(stack)
    global time
    if len(stack) == 0:
        return

    v = stack.pop()
    if results[v][0] == 0:
        time += 1
        results[v][0] = time

    es = a[v]
    if len(es) == 0 and results[v][1] == 0:
        time += 1
        results[v][1] = time

    if len(es) != 0:
        stack.append(v)
        next_vert = es.pop(0)
        if results[next_vert][0] == 0:
            stack.append(next_vert)

    depth_first_search(a, stack) depth_first_search debug(a) debug a debug(results) debug results debug(stack) debug stack global time if len(stack) == 0:
        return

     len(stack) == 0 len(stack) len stack 0 return v = stack.pop() v stack.pop() stack.pop stack pop if results[v][0] == 0:
        time += 1
        results[v][0] = time

     results[v][0] == 0 results[v][0] [v] results v 0 0 time += 1 time 1 results[v][0] = time results[v][0] [v] results v 0 time es = a[v] es a[v] a v if len(es) == 0 and results[v][1] == 0:
        time += 1
        results[v][1] = time

     len(es) == 0 and results[v][1] == 0 len(es) == 0 len(es) len es 0 results[v][1] == 0 results[v][1] [v] results v 1 0 time += 1 time 1 results[v][1] = time results[v][1] [v] results v 1 time if len(es) != 0:
        stack.append(v)
        next_vert = es.pop(0)
        if results[next_vert][0] == 0:
            stack.append(next_vert)

     len(es) != 0 len(es) len es 0 stack.append(v) stack.append stack append v next_vert = es.pop(0) next_vert es.pop(0) es.pop es pop 0 if results[next_vert][0] == 0:
            stack.append(next_vert)

     results[next_vert][0] == 0 results[next_vert][0] [next_vert] results next_vert 0 0 stack.append(next_vert) stack.append stack append next_vert depth_first_search(a, stack) depth_first_search a stack a a stack stack for i in range(n):
    stack = [i + 1]
    depth_first_search(a, stack) i range(n) range n stack = [i + 1] stack [i + 1] i + 1 i 1 depth_first_search(a, stack) depth_first_search a stack debug(results) debug results results.pop(0) results.pop results pop 0 i = 1 i 1 for row in results:
    print(str(i) + " " + str(row[0]) + " " + str(row[1]))
    i += 1 row results print(str(i) + " " + str(row[0]) + " " + str(row[1])) print str(i) + " " + str(row[0]) + " " + str(row[1]) str(i) + " " + str(row[0]) + " " str(i) + " " + str(row[0]) str(i) + " " str(i) str i " " str(row[0]) str row[0] row 0 " " str(row[1]) str row[1] row 1 i += 1 i 1 v = input().split() input().split() v level = False False level def depth_first_search(a, stack):
    debug(a)
    debug(results)
    debug(stack)
    global time
    if len(stack) == 0:
        return

    v = stack.pop()
    if results[v][0] == 0:
        time += 1
        results[v][0] = time

    es = a[v]
    if len(es) == 0 and results[v][1] == 0:
        time += 1
        results[v][1] = time

    if len(es) != 0:
        stack.append(v)
        next_vert = es.pop(0)
        if results[next_vert][0] == 0:
            stack.append(next_vert)

    depth_first_search(a, stack) def depth_first_search(a, stack):
    debug(a)
    debug(results)
    debug(stack)
    global time
    if len(stack) == 0:
        return

    v = stack.pop()
    if results[v][0] == 0:
        time += 1
        results[v][0] = time

    es = a[v]
    if len(es) == 0 and results[v][1] == 0:
        time += 1
        results[v][1] = time

    if len(es) != 0:
        stack.append(v)
        next_vert = es.pop(0)
        if results[next_vert][0] == 0:
            stack.append(next_vert)

    depth_first_search(a, stack) depth_first_search a = [0] [0] a i += 1 1 i stack = [1] [1] stack stack = [i + 1] [i + 1] stack def debug(v):
    if level:
        print(v) def debug(v):
    if level:
        print(v) debug results = [[0 for i in range(2)] for j in range(n + 1)] [[0 for i in range(2)] for j in range(n + 1)] results n = int(input()) int(input()) n time = 0 0 time i = 1 1 i
# -*- coding: utf_8 -*-

level = False
def debug(v):
    if level:
        print(v)

n = int(input())
a = [0]

for i in range(n):
    v = input().split()
    v.pop(0)
    v.pop(0)
    a.append([int(x) for x in v])

debug(a)
stack = [1]
results = [[0 for i in range(2)] for j in range(n + 1)]
results[0][0] = 0
time = 0

def depth_first_search(a, stack):
    debug(a)
    debug(results)
    debug(stack)
    global time
    if len(stack) == 0:
        return

    v = stack.pop()
    if results[v][0] == 0:
        time += 1
        results[v][0] = time

    es = a[v]
    if len(es) == 0 and results[v][1] == 0:
        time += 1
        results[v][1] = time

    if len(es) != 0:
        stack.append(v)
        next_vert = es.pop(0)
        if results[next_vert][0] == 0:
            stack.append(next_vert)

    depth_first_search(a, stack)

for i in range(n):
    stack = [i + 1]
    depth_first_search(a, stack)

debug(results)

results.pop(0)

i = 1
for row in results:
    print(str(i) + " " + str(row[0]) + " " + str(row[1]))
    i += 1