ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return

n = ii()
t = tree(n)

for i in range(n):
    vk = li()
    u = vk[0]
    k = vk[1]
    v = vk[2:]
    t.add(u-1,v)

for i in range(n):
    t.search(i)

for i in range(n):
    print(i+1, t.start[i], t.finish[i])
 ii = lambda : int(input()) ii lambda : int(input()) int(input()) int input() input mi = lambda : map(int,input().split()) mi lambda : map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split li = lambda : list(map(int,input().split())) li lambda : list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return tree def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
     __init__ self.n = n self.n self n n self.vlist = [None]*self.n self.vlist self vlist [None]*self.n [None] None self.n self n self.start = [None]*self.n self.start self start [None]*self.n [None] None self.n self n self.finish = [None]*self.n self.finish self finish [None]*self.n [None] None self.n self n self.time = 0 self.time self time 0 self self n n def add(self,n,v):
        v.sort()
        self.vlist[n] = v

     add v.sort() v.sort v sort self.vlist[n] = v self.vlist[n] self.vlist self vlist n v self self n n v v def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return search if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return self.start[u] != None self.start[u] self.start self start u None return self.time += 1 self.time self time 1 self.start[u] = self.time self.start[u] self.start self start u self.time self time for i in self.vlist[u]:
                self.search(i-1)

             i self.vlist[u] self.vlist self vlist u self.search(i-1) self.search self search i-1 i 1 self.time += 1 self.time self time 1 self.finish[u] = self.time self.finish[u] self.finish self finish u self.time self time return self self u u n = ii() n ii() ii t = tree(n) t tree(n) tree n for i in range(n):
    vk = li()
    u = vk[0]
    k = vk[1]
    v = vk[2:]
    t.add(u-1,v) i range(n) range n vk = li() vk li() li u = vk[0] u vk[0] vk 0 k = vk[1] k vk[1] vk 1 v = vk[2:] v vk[2:] vk 2: 2 t.add(u-1,v) t.add t add u-1 u 1 v for i in range(n):
    t.search(i) i range(n) range n t.search(i) t.search t search i for i in range(n):
    print(i+1, t.start[i], t.finish[i]) i range(n) range n print(i+1, t.start[i], t.finish[i]) print i+1 i 1 t.start[i] t.start t start i t.finish[i] t.finish t finish i n = ii() ii() n v = vk[2:] vk[2:] v u = vk[0] vk[0] u vk = li() li() vk t = tree(n) tree(n) t k = vk[1] vk[1] k ii = lambda : int(input()) lambda : int(input()) ii mi = lambda : map(int,input().split()) lambda : map(int,input().split()) mi li = lambda : list(map(int,input().split())) lambda : list(map(int,input().split())) li class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return tree
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return

n = ii()
t = tree(n)

for i in range(n):
    vk = li()
    u = vk[0]
    k = vk[1]
    v = vk[2:]
    t.add(u-1,v)

for i in range(n):
    t.search(i)

for i in range(n):
    print(i+1, t.start[i], t.finish[i])

