# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
# Depth First Search
# Result:
import sys

class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

    def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_

class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_



s = int(sys.stdin.readline().strip())
graph = Graph(s)
for _ in range(0, s):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    v = Vertex(vals[0])
    graph.add_vertex(v)
    if vals[1] == 0: continue
    for i in range(0, vals[1]):
        v.add_adjacent(vals[2 + i])

graph.depth_first_search() import sys sys class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

    def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_ Graph def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

     __init__ super(Graph, self).__init__() (Graph, self).__init__ (Graph, self) super Graph self __init__ self.__size = size self.__size self __size size self.__vertices = [None] * size self.__vertices self __vertices [None] * size [None] None size self self size size def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

     add_vertex self.__vertices[vertex.id_ - 1] = vertex self.__vertices[vertex.id_ - 1] self.__vertices self __vertices vertex.id_ - 1 vertex.id_ vertex id_ 1 vertex self self vertex vertex def get_vertex(self, vid):
        return self.__vertices[vid - 1]

     get_vertex return self.__vertices[vid - 1] self.__vertices[vid - 1] self.__vertices self __vertices vid - 1 vid 1 self self vid vid def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

     depth_first_search d = [0] * self.__size d [0] * self.__size [0] 0 self.__size self __size f = [0] * self.__size f [0] * self.__size [0] 0 self.__size self __size timer = 1 timer 1 for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

         j range(1, self.__size + 1) range 1 self.__size + 1 self.__size self __size 1 vtx = self.get_vertex(j) vtx self.get_vertex(j) self.get_vertex self get_vertex j if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

         not vtx.visited vtx.visited vtx visited stack = [vtx] stack [vtx] vtx d[vtx.id_ - 1] = timer d[vtx.id_ - 1] d vtx.id_ - 1 vtx.id_ vtx id_ 1 timer vtx.visited = True vtx.visited vtx visited True timer = self.__depth_first_search(stack, timer, d, f) + 1 timer self.__depth_first_search(stack, timer, d, f) + 1 self.__depth_first_search(stack, timer, d, f) self.__depth_first_search self __depth_first_search stack timer d f 1 for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

     vtx self.__vertices self __vertices print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1]) '%d %d %d' (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1]) vtx.id_ vtx id_ d[vtx.id_ - 1] d vtx.id_ - 1 vtx.id_ vtx id_ 1 f[vtx.id_ - 1] f vtx.id_ - 1 vtx.id_ vtx id_ 1 self self def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

     __depth_first_search while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
         len(stack) > 0 len(stack) len stack 0 top = stack[-1] top stack[-1] stack -1 avid = top.get_next_adjacnt() avid top.get_next_adjacnt() top.get_next_adjacnt top get_next_adjacnt if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
         avid == -1 avid -1 timer += 1 timer 1 f[top.id_ - 1] = timer f[top.id_ - 1] f top.id_ - 1 top.id_ top id_ 1 timer stack.pop() stack.pop stack pop av = self.get_vertex(avid) av self.get_vertex(avid) self.get_vertex self get_vertex avid if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
         not av.visited av.visited av visited timer += 1 timer 1 stack.append(av) stack.append stack append av d[av.id_ - 1] = timer d[av.id_ - 1] d av.id_ - 1 av.id_ av id_ 1 timer av.visited = True av.visited av visited True return timer timer self self stack stack timer timer d d f f def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_ __str__ str_ = '' str_ '' for e in self.__vertices:
            str_ += '%s\n' % e
         e self.__vertices self __vertices str_ += '%s\n' % e str_ '%s\n' % e '%s\n' e return str_ str_ self self object class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_ Vertex def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

     __init__ super(Vertex, self).__init__() (Vertex, self).__init__ (Vertex, self) super Vertex self __init__ self.id_ = id_ self.id_ self id_ id_ self.adjacents = [] self.adjacents self adjacents [] self.next_idx = 0 self.next_idx self next_idx 0 self.visited = False self.visited self visited False self self id_ id_ def add_adjacent(self, avid):
        self.adjacents.append(avid)

     add_adjacent self.adjacents.append(avid) self.adjacents.append self.adjacents self adjacents append avid self self avid avid def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

     get_next_adjacnt if len(self.adjacents) == 0: return -1
         len(self.adjacents) == 0 len(self.adjacents) len self.adjacents self adjacents 0 if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

     self.next_idx < len(self.adjacents) self.next_idx self next_idx len(self.adjacents) len self.adjacents self adjacents val = self.adjacents[self.next_idx] val self.adjacents[self.next_idx] self.adjacents self adjacents self.next_idx self next_idx self.next_idx += 1 self.next_idx self next_idx 1 return val val return -1 -1 self self def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_ __str__ str_ = '%d ' % self.id_ str_ '%d ' % self.id_ '%d ' self.id_ self id_ if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
         len(self.adjacents) == 0 len(self.adjacents) len self.adjacents self adjacents 0 str_ += '0' str_ '0' str_ += '%d' % len(self.adjacents) str_ '%d' % len(self.adjacents) '%d' len(self.adjacents) len self.adjacents self adjacents for e in self.adjacents:
                str_ += ' %d' % e
         e self.adjacents self adjacents str_ += ' %d' % e str_ ' %d' % e ' %d' e return str_ str_ self self object s = int(sys.stdin.readline().strip()) s 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 = Graph(s) graph Graph(s) Graph s for _ in range(0, s):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    v = Vertex(vals[0])
    graph.add_vertex(v)
    if vals[1] == 0: continue
    for i in range(0, vals[1]):
        v.add_adjacent(vals[2 + i]) _ range(0, s) range 0 s int(x) for x in sys.stdin.readline().strip().split(' ') for x in sys.stdin.readline().strip().split(' ') x 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 ' ' for x in sys.stdin.readline().strip().split(' ') int(x) int x vals = [int(x) for x in sys.stdin.readline().strip().split(' ')] vals [int(x) for x in sys.stdin.readline().strip().split(' ')] v = Vertex(vals[0]) v Vertex(vals[0]) Vertex vals[0] vals 0 graph.add_vertex(v) graph.add_vertex graph add_vertex v if vals[1] == 0: continue
     vals[1] == 0 vals[1] vals 1 0 for i in range(0, vals[1]):
        v.add_adjacent(vals[2 + i]) i range(0, vals[1]) range 0 vals[1] vals 1 v.add_adjacent(vals[2 + i]) v.add_adjacent v add_adjacent vals[2 + i] vals 2 + i 2 i graph.depth_first_search() graph.depth_first_search graph depth_first_search class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

    def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_ class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

    def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_ Graph graph = Graph(s) Graph(s) graph v = Vertex(vals[0]) Vertex(vals[0]) v vals = [int(x) for x in sys.stdin.readline().strip().split(' ')] [int(x) for x in sys.stdin.readline().strip().split(' ')] vals class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_ class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_ Vertex s = int(sys.stdin.readline().strip()) int(sys.stdin.readline().strip()) s
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
# Depth First Search
# Result:
import sys

class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

    def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_

class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_



s = int(sys.stdin.readline().strip())
graph = Graph(s)
for _ in range(0, s):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    v = Vertex(vals[0])
    graph.add_vertex(v)
    if vals[1] == 0: continue
    for i in range(0, vals[1]):
        v.add_adjacent(vals[2 + i])

graph.depth_first_search()