from collections import deque

#スタックを使った深さ優先探索の実装
l = int(input())
rlist = []
for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(deque([ll-1 for ll in li[2:]]))


color = ['white'] * l
find_time = [0] * l
stop_time = [0] * l
stack = []
time = 0

def dfs(u):
    global time

    stack.append(u)
    color[u] = 'gray'
    time += 1
    find_time[u] = time

    while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop()

for i in range(l):
    if color[i] == 'white':
        dfs(i)
for i in range(len(find_time)):
    print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i])) from collections import deque l = int(input()) l int(input()) int input() input rlist = [] rlist [] for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(deque([ll-1 for ll in li[2:]])) i range(l) range l li = list(map(int, input().split())) li list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ll-1 for ll in li[2:] for ll in li[2:] ll li[2:] li 2: 2 for ll in li[2:] ll-1 ll 1 rlist.append(deque([ll-1 for ll in li[2:]])) rlist.append rlist append deque([ll-1 for ll in li[2:]]) deque [ll-1 for ll in li[2:]] color = ['white'] * l color ['white'] * l ['white'] 'white' l find_time = [0] * l find_time [0] * l [0] 0 l stop_time = [0] * l stop_time [0] * l [0] 0 l stack = [] stack [] time = 0 time 0 def dfs(u):
    global time

    stack.append(u)
    color[u] = 'gray'
    time += 1
    find_time[u] = time

    while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop() dfs global time stack.append(u) stack.append stack append u color[u] = 'gray' color[u] color u 'gray' time += 1 time 1 find_time[u] = time find_time[u] find_time u time while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop() len(stack) > 0 len(stack) len stack 0 u = stack[-1] u stack[-1] stack -1 if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop() len(rlist[u]) > 0 len(rlist[u]) len rlist[u] rlist u 0 if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
             color[rlist[u][0]] == 'white' color[rlist[u][0]] color rlist[u][0] [u] rlist u 0 'white' time += 1 time 1 find_time[rlist[u][0]] = time find_time[rlist[u][0]] find_time rlist[u][0] [u] rlist u 0 time color[rlist[u][0]] = 'gray' color[rlist[u][0]] color rlist[u][0] [u] rlist u 0 'gray' stack.append(rlist[u][0]) stack.append stack append rlist[u][0] [u] rlist u 0 rlist[u].popleft() [u].popleft [u] rlist u popleft time += 1 time 1 stop_time[u] = time stop_time[u] stop_time u time color[u] = 'black' color[u] color u 'black' stack.pop() stack.pop stack pop u u for i in range(l):
    if color[i] == 'white':
        dfs(i) i range(l) range l if color[i] == 'white':
        dfs(i) color[i] == 'white' color[i] color i 'white' dfs(i) dfs i for i in range(len(find_time)):
    print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i])) i range(len(find_time)) range len(find_time) len find_time print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i])) print str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i]) str(i+1) + ' ' + str(find_time[i]) + ' ' str(i+1) + ' ' + str(find_time[i]) str(i+1) + ' ' str(i+1) str i+1 i 1 ' ' str(find_time[i]) str find_time[i] find_time i ' ' str(stop_time[i]) str stop_time[i] stop_time i stop_time = [0] * l [0] * l stop_time time = 0 0 time find_time = [0] * l [0] * l find_time l = int(input()) int(input()) l li = list(map(int, input().split())) list(map(int, input().split())) li color = ['white'] * l ['white'] * l color stack = [] [] stack def dfs(u):
    global time

    stack.append(u)
    color[u] = 'gray'
    time += 1
    find_time[u] = time

    while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop() def dfs(u):
    global time

    stack.append(u)
    color[u] = 'gray'
    time += 1
    find_time[u] = time

    while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop() dfs rlist = [] [] rlist
from collections import deque

#スタックを使った深さ優先探索の実装
l = int(input())
rlist = []
for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(deque([ll-1 for ll in li[2:]]))


color = ['white'] * l
find_time = [0] * l
stop_time = [0] * l
stack = []
time = 0

def dfs(u):
    global time

    stack.append(u)
    color[u] = 'gray'
    time += 1
    find_time[u] = time

    while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop()

for i in range(l):
    if color[i] == 'white':
        dfs(i)
for i in range(len(find_time)):
    print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i]))
