import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
    input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
detect_time = [0] * n
finish_time = [0] * n
is_visit = [False] * n
stack = []
time = 0

while(time < n*2):
    time += 1
    id = is_visit.index(False) + 1
    stack.append(id)
    is_visit[id-1] = True
    detect_time[id-1] = time
    while(len(stack) != 0):
        id = stack[-1]
        if len(input_line[id-1]) == 0:
            time += 1
            finish_time[stack.pop()-1] = time
        else:
            detect_id = input_line[id-1].pop(0)
            if is_visit[detect_id-1]:
                continue
            stack.append(detect_id)
            time += 1
            detect_time[detect_id-1] = time
            is_visit[detect_id-1] = True


for id in range(n):
    print('{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id])) import sys sys n = int(input()) n int(input()) int input() input [int(i) for i in str.split()] for str in sys.stdin.read().splitlines() for str in sys.stdin.read().splitlines() str sys.stdin.read().splitlines() sys.stdin.read().splitlines sys.stdin.read() sys.stdin.read sys.stdin sys stdin read splitlines for str in sys.stdin.read().splitlines() [int(i) for i in str.split()] input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()] input_line [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()] for i in range(n):
    input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:] i range(n) range n input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:] input_line[i] input_line i [] if len(input_line[i]) == 2 else input_line[i][2:] len(input_line[i]) == 2 len(input_line[i]) len input_line[i] input_line i 2 [] input_line[i][2:] [i] input_line i 2: 2 detect_time = [0] * n detect_time [0] * n [0] 0 n finish_time = [0] * n finish_time [0] * n [0] 0 n is_visit = [False] * n is_visit [False] * n [False] False n stack = [] stack [] time = 0 time 0 while(time < n*2):
    time += 1
    id = is_visit.index(False) + 1
    stack.append(id)
    is_visit[id-1] = True
    detect_time[id-1] = time
    while(len(stack) != 0):
        id = stack[-1]
        if len(input_line[id-1]) == 0:
            time += 1
            finish_time[stack.pop()-1] = time
        else:
            detect_id = input_line[id-1].pop(0)
            if is_visit[detect_id-1]:
                continue
            stack.append(detect_id)
            time += 1
            detect_time[detect_id-1] = time
            is_visit[detect_id-1] = True time < n*2 time n*2 n 2 time += 1 time 1 id = is_visit.index(False) + 1 id is_visit.index(False) + 1 is_visit.index(False) is_visit.index is_visit index False 1 stack.append(id) stack.append stack append id is_visit[id-1] = True is_visit[id-1] is_visit id-1 id 1 True detect_time[id-1] = time detect_time[id-1] detect_time id-1 id 1 time while(len(stack) != 0):
        id = stack[-1]
        if len(input_line[id-1]) == 0:
            time += 1
            finish_time[stack.pop()-1] = time
        else:
            detect_id = input_line[id-1].pop(0)
            if is_visit[detect_id-1]:
                continue
            stack.append(detect_id)
            time += 1
            detect_time[detect_id-1] = time
            is_visit[detect_id-1] = True len(stack) != 0 len(stack) len stack 0 id = stack[-1] id stack[-1] stack -1 if len(input_line[id-1]) == 0:
            time += 1
            finish_time[stack.pop()-1] = time
        else:
            detect_id = input_line[id-1].pop(0)
            if is_visit[detect_id-1]:
                continue
            stack.append(detect_id)
            time += 1
            detect_time[detect_id-1] = time
            is_visit[detect_id-1] = True len(input_line[id-1]) == 0 len(input_line[id-1]) len input_line[id-1] input_line id-1 id 1 0 time += 1 time 1 finish_time[stack.pop()-1] = time finish_time[stack.pop()-1] finish_time stack.pop()-1 stack.pop() stack.pop stack pop 1 time detect_id = input_line[id-1].pop(0) detect_id input_line[id-1].pop(0) [id-1].pop [id-1] input_line id-1 id 1 pop 0 if is_visit[detect_id-1]:
                continue
             is_visit[detect_id-1] is_visit detect_id-1 detect_id 1 continue stack.append(detect_id) stack.append stack append detect_id time += 1 time 1 detect_time[detect_id-1] = time detect_time[detect_id-1] detect_time detect_id-1 detect_id 1 time is_visit[detect_id-1] = True is_visit[detect_id-1] is_visit detect_id-1 detect_id 1 True for id in range(n):
    print('{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id])) id range(n) range n print('{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id])) print '{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id]) '{0} {1} {2}'.format '{0} {1} {2}' format id+1 id 1 detect_time[id] detect_time id finish_time[id] finish_time id finish_time = [0] * n [0] * n finish_time time = 0 0 time time += 1 1 time id = stack[-1] stack[-1] id stack = [] [] stack input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()] [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()] input_line time += 1 1 time time += 1 1 time detect_id = input_line[id-1].pop(0) input_line[id-1].pop(0) detect_id detect_time = [0] * n [0] * n detect_time is_visit = [False] * n [False] * n is_visit id = is_visit.index(False) + 1 is_visit.index(False) + 1 id n = int(input()) int(input()) n
import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
    input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
detect_time = [0] * n
finish_time = [0] * n
is_visit = [False] * n
stack = []
time = 0

while(time < n*2):
    time += 1
    id = is_visit.index(False) + 1
    stack.append(id)
    is_visit[id-1] = True
    detect_time[id-1] = time
    while(len(stack) != 0):
        id = stack[-1]
        if len(input_line[id-1]) == 0:
            time += 1
            finish_time[stack.pop()-1] = time
        else:
            detect_id = input_line[id-1].pop(0)
            if is_visit[detect_id-1]:
                continue
            stack.append(detect_id)
            time += 1
            detect_time[detect_id-1] = time
            is_visit[detect_id-1] = True


for id in range(n):
    print('{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id]))
