n = int(input())

class Node:
    def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
    def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt)

Nodes = [None] * n
for i in range(n):
    row = [int(tt) for tt in input().split()]
    Nodes[row[0]-1] = Node(row[0], [ row[j + 2] for j in range(row[1])])
        
def depthSearch(Nodes):
    stack = [Nodes[0]]
    
    time = 2
    current = stack[-1]
    current.foundAt = 1
    while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
    return Nodes
Nodes = depthSearch(Nodes)
for node in Nodes:
    print(node) n = int(input()) n int(input()) int input() input class Node:
    def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
    def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt) Node def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
     __init__ self.idd = idd self.idd self idd idd self.neighbors = neighbors self.neighbors self neighbors neighbors self.foundAt = 0 self.foundAt self foundAt 0 self.completeAt = 0 self.completeAt self completeAt 0 self self idd idd neighbors neighbors def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt) __repr__ return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt) "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt) "{0} {1} {2}".format "{0} {1} {2}" format self.idd self idd self.foundAt self foundAt self.completeAt self completeAt self self Nodes = [None] * n Nodes [None] * n [None] None n for i in range(n):
    row = [int(tt) for tt in input().split()]
    Nodes[row[0]-1] = Node(row[0], [ row[j + 2] for j in range(row[1])])
         i range(n) range n int(tt) for tt in input().split() for tt in input().split() tt input().split() ().split () input split for tt in input().split() int(tt) int tt row = [int(tt) for tt in input().split()] row [int(tt) for tt in input().split()] row[j + 2] for j in range(row[1]) for j in range(row[1]) j range(row[1]) range row[1] row 1 for j in range(row[1]) row[j + 2] row j + 2 j 2 Nodes[row[0]-1] = Node(row[0], [ row[j + 2] for j in range(row[1])]) Nodes[row[0]-1] Nodes row[0]-1 row[0] row 0 1 Node(row[0], [ row[j + 2] for j in range(row[1])]) Node row[0] row 0 [ row[j + 2] for j in range(row[1])] def depthSearch(Nodes):
    stack = [Nodes[0]]
    
    time = 2
    current = stack[-1]
    current.foundAt = 1
    while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
    return Nodes depthSearch stack = [Nodes[0]] stack [Nodes[0]] Nodes[0] Nodes 0 time = 2 time 2 current = stack[-1] current stack[-1] stack -1 current.foundAt = 1 current.foundAt current foundAt 1 while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
     len(stack) > 0 or any([node.foundAt==0 for node in Nodes]) len(stack) > 0 len(stack) len stack 0 any([node.foundAt==0 for node in Nodes]) any [node.foundAt==0 for node in Nodes] if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
         len(stack)==0 len(stack) len stack 0 node for node in Nodes if node.foundAt==0 for node in Nodes if node.foundAt==0 node Nodes node.foundAt==0 node.foundAt node foundAt 0 if node.foundAt==0 node newStart = [node for node in Nodes if node.foundAt==0][0] newStart [node for node in Nodes if node.foundAt==0][0] [node for node in Nodes if node.foundAt==0] 0 newStart.foundAt = time newStart.foundAt newStart foundAt time stack.append(newStart) stack.append stack append newStart time += 1 time 1 current = stack[-1] current stack[-1] stack -1 if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
         len(current.neighbors) > 0 len(current.neighbors) len current.neighbors current neighbors 0 next_n = Nodes[current.neighbors.pop(0)-1] next_n Nodes[current.neighbors.pop(0)-1] Nodes current.neighbors.pop(0)-1 current.neighbors.pop(0) current.neighbors.pop current.neighbors current neighbors pop 0 1 if(next_n.foundAt != 0):
                continue
             next_n.foundAt != 0 next_n.foundAt next_n foundAt 0 continue next_n.foundAt = time next_n.foundAt next_n foundAt time stack.append(next_n) stack.append stack append next_n current.completeAt = time current.completeAt current completeAt time stack.pop(-1) stack.pop stack pop -1 time += 1 time 1 return Nodes Nodes Nodes Nodes Nodes = depthSearch(Nodes) Nodes depthSearch(Nodes) depthSearch Nodes for node in Nodes:
    print(node) node Nodes print(node) print node Nodes = depthSearch(Nodes) depthSearch(Nodes) Nodes row = [int(tt) for tt in input().split()] [int(tt) for tt in input().split()] row n = int(input()) int(input()) n class Node:
    def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
    def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt) class Node:
    def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
    def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt) Node Nodes = [None] * n [None] * n Nodes def depthSearch(Nodes):
    stack = [Nodes[0]]
    
    time = 2
    current = stack[-1]
    current.foundAt = 1
    while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
    return Nodes def depthSearch(Nodes):
    stack = [Nodes[0]]
    
    time = 2
    current = stack[-1]
    current.foundAt = 1
    while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
    return Nodes depthSearch
n = int(input())

class Node:
    def __init__(self, idd, neighbors):
        self.idd = idd
        self.neighbors = neighbors
        self.foundAt = 0
        self.completeAt = 0
        
    def __repr__(self):
        return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt)

Nodes = [None] * n
for i in range(n):
    row = [int(tt) for tt in input().split()]
    Nodes[row[0]-1] = Node(row[0], [ row[j + 2] for j in range(row[1])])
        
def depthSearch(Nodes):
    stack = [Nodes[0]]
    
    time = 2
    current = stack[-1]
    current.foundAt = 1
    while len(stack) > 0 or any([node.foundAt==0 for node in Nodes]):
        if(len(stack)==0):
            newStart = [node for node in Nodes if node.foundAt==0][0]
            newStart.foundAt = time
            stack.append(newStart)
            time += 1
        current = stack[-1]
        if(len(current.neighbors) > 0):
            next_n = Nodes[current.neighbors.pop(0)-1]
            if(next_n.foundAt != 0):
                continue
            next_n.foundAt = time
            stack.append(next_n)
        else:
            current.completeAt = time
            stack.pop(-1)
        time += 1
    return Nodes
Nodes = depthSearch(Nodes)
for node in Nodes:
    print(node)
