import sys

d_num = int(sys.stdin.readline().strip())

graph_list = []

for _ in range(0, d_num):
    array = sys.stdin.readline().strip().split(" ")
    if len(array) <= 2:
        graph_list.append([])
    else:
        graph_list.append([int(array[i]) - 1 for i in range(2, len(array))])

t = 1
result = [[] for _ in range(0, d_num)]
searched_list = []
stack = []

while True:
    if len(stack) == 0:
        ll = filter(lambda x: x not in searched_list, range(0, d_num))
        if len(ll) == 0:
            break
        stack.append(ll[0])
        result[ll[0]].append(t)
        searched_list.append(ll[0])
    else:
        node = stack[-1]
        children = filter(lambda x: x not in searched_list, graph_list[node])
        if len(children) != 0:
            next_node = children[0]
            stack.append(next_node)
            result[next_node].append(t)
            searched_list.append(next_node)
        else:
            stack.pop()
            result[node].append(t)
    t += 1

s = ""

for i in range(0, len(result)):
    print str(i+1) + " " + str(result[i][0]) + " " + str(result[i][1]) import sys sys d_num = int(sys.stdin.readline().strip()) d_num int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip graph_list = [] graph_list [] for _ in range(0, d_num):
    array = sys.stdin.readline().strip().split(" ")
    if len(array) <= 2:
        graph_list.append([])
    else:
        graph_list.append([int(array[i]) - 1 for i in range(2, len(array))]) _ range(0, d_num) range 0 d_num array = sys.stdin.readline().strip().split(" ") array sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " if len(array) <= 2:
        graph_list.append([])
    else:
        graph_list.append([int(array[i]) - 1 for i in range(2, len(array))]) len(array) <= 2 len(array) len array 2 graph_list.append([]) graph_list.append graph_list append [] int(array[i]) - 1 for i in range(2, len(array)) for i in range(2, len(array)) i range(2, len(array)) range 2 len(array) len array for i in range(2, len(array)) int(array[i]) - 1 int(array[i]) int array[i] array i 1 graph_list.append([int(array[i]) - 1 for i in range(2, len(array))]) graph_list.append graph_list append [int(array[i]) - 1 for i in range(2, len(array))] t = 1 t 1 [] for _ in range(0, d_num) for _ in range(0, d_num) _ range(0, d_num) range 0 d_num for _ in range(0, d_num) [] result = [[] for _ in range(0, d_num)] result [[] for _ in range(0, d_num)] searched_list = [] searched_list [] stack = [] stack [] while True:
    if len(stack) == 0:
        ll = filter(lambda x: x not in searched_list, range(0, d_num))
        if len(ll) == 0:
            break
        stack.append(ll[0])
        result[ll[0]].append(t)
        searched_list.append(ll[0])
    else:
        node = stack[-1]
        children = filter(lambda x: x not in searched_list, graph_list[node])
        if len(children) != 0:
            next_node = children[0]
            stack.append(next_node)
            result[next_node].append(t)
            searched_list.append(next_node)
        else:
            stack.pop()
            result[node].append(t)
    t += 1 True if len(stack) == 0:
        ll = filter(lambda x: x not in searched_list, range(0, d_num))
        if len(ll) == 0:
            break
        stack.append(ll[0])
        result[ll[0]].append(t)
        searched_list.append(ll[0])
    else:
        node = stack[-1]
        children = filter(lambda x: x not in searched_list, graph_list[node])
        if len(children) != 0:
            next_node = children[0]
            stack.append(next_node)
            result[next_node].append(t)
            searched_list.append(next_node)
        else:
            stack.pop()
            result[node].append(t)
     len(stack) == 0 len(stack) len stack 0 ll = filter(lambda x: x not in searched_list, range(0, d_num)) ll filter(lambda x: x not in searched_list, range(0, d_num)) filter lambda x: x not in searched_list x not in searched_list x searched_list x range(0, d_num) range 0 d_num if len(ll) == 0:
            break
         len(ll) == 0 len(ll) len ll 0 break stack.append(ll[0]) stack.append stack append ll[0] ll 0 result[ll[0]].append(t) [ll[0]].append [ll[0]] result ll[0] ll 0 append t searched_list.append(ll[0]) searched_list.append searched_list append ll[0] ll 0 node = stack[-1] node stack[-1] stack -1 children = filter(lambda x: x not in searched_list, graph_list[node]) children filter(lambda x: x not in searched_list, graph_list[node]) filter lambda x: x not in searched_list x not in searched_list x searched_list x graph_list[node] graph_list node if len(children) != 0:
            next_node = children[0]
            stack.append(next_node)
            result[next_node].append(t)
            searched_list.append(next_node)
        else:
            stack.pop()
            result[node].append(t)
     len(children) != 0 len(children) len children 0 next_node = children[0] next_node children[0] children 0 stack.append(next_node) stack.append stack append next_node result[next_node].append(t) [next_node].append [next_node] result next_node append t searched_list.append(next_node) searched_list.append searched_list append next_node stack.pop() stack.pop stack pop result[node].append(t) [node].append [node] result node append t t += 1 t 1 s = "" s "" for i in range(0, len(result)):
    print str(i+1) + " " + str(result[i][0]) + " " + str(result[i][1]) i range(0, len(result)) range 0 len(result) len result print str(i+1) + " " + str(result[i][0]) + " " + str(result[i][1]) str(i+1) + " " + str(result[i][0]) + " " str(i+1) + " " + str(result[i][0]) str(i+1) + " " str(i+1) str i+1 i 1 " " str(result[i][0]) str result[i][0] [i] result i 0 " " str(result[i][1]) str result[i][1] [i] result i 1 graph_list = [] [] graph_list children = filter(lambda x: x not in searched_list, graph_list[node]) filter(lambda x: x not in searched_list, graph_list[node]) children node = stack[-1] stack[-1] node d_num = int(sys.stdin.readline().strip()) int(sys.stdin.readline().strip()) d_num result = [[] for _ in range(0, d_num)] [[] for _ in range(0, d_num)] result searched_list = [] [] searched_list t += 1 1 t s = "" "" s t = 1 1 t ll = filter(lambda x: x not in searched_list, range(0, d_num)) filter(lambda x: x not in searched_list, range(0, d_num)) ll array = sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split(" ") array stack = [] [] stack next_node = children[0] children[0] next_node
import sys

d_num = int(sys.stdin.readline().strip())

graph_list = []

for _ in range(0, d_num):
    array = sys.stdin.readline().strip().split(" ")
    if len(array) <= 2:
        graph_list.append([])
    else:
        graph_list.append([int(array[i]) - 1 for i in range(2, len(array))])

t = 1
result = [[] for _ in range(0, d_num)]
searched_list = []
stack = []

while True:
    if len(stack) == 0:
        ll = filter(lambda x: x not in searched_list, range(0, d_num))
        if len(ll) == 0:
            break
        stack.append(ll[0])
        result[ll[0]].append(t)
        searched_list.append(ll[0])
    else:
        node = stack[-1]
        children = filter(lambda x: x not in searched_list, graph_list[node])
        if len(children) != 0:
            next_node = children[0]
            stack.append(next_node)
            result[next_node].append(t)
            searched_list.append(next_node)
        else:
            stack.pop()
            result[node].append(t)
    t += 1

s = ""

for i in range(0, len(result)):
    print str(i+1) + " " + str(result[i][0]) + " " + str(result[i][1])