class Node:
    def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0

N = int(input())
work_id = 0
nodes = list()
nodes.append(Node(0))


for _ in range(N):
    tmp_list = list( map(int, input().split()) )
    node = Node(tmp_list[0])
    for i in range(tmp_list[1]):
        node.neighbors.append(tmp_list[i+2])
    nodes.append(node)
    nodes[0].neighbors.append(node.data)

# for node in nodes:
#     print(node.data, ":", node.neighbors)


def search(node):
    global work_id

    if node.find_time != 0:
        return
    
    if node.data != 0:
        work_id += 1
        node.find_time = work_id

    if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
    if node.data != 0:
        work_id += 1
        node.end_time = work_id

search(nodes[0])

for node in nodes:
    if node.data == 0: continue
    print(node.data, node.find_time, node.end_time)
 class Node:
    def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0 Node def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0 __init__ self.data = data self.data self data data self.neighbors = list() self.neighbors self neighbors list() list self.find_time = 0 self.find_time self find_time 0 self.end_time = 0 self.end_time self end_time 0 self self data data N = int(input()) N int(input()) int input() input work_id = 0 work_id 0 nodes = list() nodes list() list nodes.append(Node(0)) nodes.append nodes append Node(0) Node 0 for _ in range(N):
    tmp_list = list( map(int, input().split()) )
    node = Node(tmp_list[0])
    for i in range(tmp_list[1]):
        node.neighbors.append(tmp_list[i+2])
    nodes.append(node)
    nodes[0].neighbors.append(node.data)

# for node in nodes:
#     print(node.data, ":", node.neighbors) _ range(N) range N tmp_list = list( map(int, input().split()) ) tmp_list list( map(int, input().split()) ) list map(int, input().split()) map int input().split() ().split () input split node = Node(tmp_list[0]) node Node(tmp_list[0]) Node tmp_list[0] tmp_list 0 for i in range(tmp_list[1]):
        node.neighbors.append(tmp_list[i+2])
     i range(tmp_list[1]) range tmp_list[1] tmp_list 1 node.neighbors.append(tmp_list[i+2]) node.neighbors.append node.neighbors node neighbors append tmp_list[i+2] tmp_list i+2 i 2 nodes.append(node) nodes.append nodes append node nodes[0].neighbors.append(node.data) [0].neighbors.append [0].neighbors [0] nodes 0 neighbors append node.data node data def search(node):
    global work_id

    if node.find_time != 0:
        return
    
    if node.data != 0:
        work_id += 1
        node.find_time = work_id

    if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
    if node.data != 0:
        work_id += 1
        node.end_time = work_id search global work_id if node.find_time != 0:
        return
    
     node.find_time != 0 node.find_time node find_time 0 return if node.data != 0:
        work_id += 1
        node.find_time = work_id

     node.data != 0 node.data node data 0 work_id += 1 work_id 1 node.find_time = work_id node.find_time node find_time work_id if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
     len(node.neighbors) > 0 len(node.neighbors) len node.neighbors node neighbors 0 for neighbor in node.neighbors:
            search(nodes[neighbor])
    
     neighbor node.neighbors node neighbors search(nodes[neighbor]) search nodes[neighbor] nodes neighbor if node.data != 0:
        work_id += 1
        node.end_time = work_id node.data != 0 node.data node data 0 work_id += 1 work_id 1 node.end_time = work_id node.end_time node end_time work_id node node search(nodes[0]) search nodes[0] nodes 0 for node in nodes:
    if node.data == 0: continue
    print(node.data, node.find_time, node.end_time) node nodes if node.data == 0: continue
     node.data == 0 node.data node data 0 print(node.data, node.find_time, node.end_time) print node.data node data node.find_time node find_time node.end_time node end_time N = int(input()) int(input()) N node = Node(tmp_list[0]) Node(tmp_list[0]) node work_id = 0 0 work_id nodes = list() list() nodes def search(node):
    global work_id

    if node.find_time != 0:
        return
    
    if node.data != 0:
        work_id += 1
        node.find_time = work_id

    if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
    if node.data != 0:
        work_id += 1
        node.end_time = work_id def search(node):
    global work_id

    if node.find_time != 0:
        return
    
    if node.data != 0:
        work_id += 1
        node.find_time = work_id

    if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
    if node.data != 0:
        work_id += 1
        node.end_time = work_id search class Node:
    def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0 class Node:
    def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0 Node tmp_list = list( map(int, input().split()) ) list( map(int, input().split()) ) tmp_list
class Node:
    def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0

N = int(input())
work_id = 0
nodes = list()
nodes.append(Node(0))


for _ in range(N):
    tmp_list = list( map(int, input().split()) )
    node = Node(tmp_list[0])
    for i in range(tmp_list[1]):
        node.neighbors.append(tmp_list[i+2])
    nodes.append(node)
    nodes[0].neighbors.append(node.data)

# for node in nodes:
#     print(node.data, ":", node.neighbors)


def search(node):
    global work_id

    if node.find_time != 0:
        return
    
    if node.data != 0:
        work_id += 1
        node.find_time = work_id

    if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
    if node.data != 0:
        work_id += 1
        node.end_time = work_id

search(nodes[0])

for node in nodes:
    if node.data == 0: continue
    print(node.data, node.find_time, node.end_time)

