from sys import stdin

global time
time = 0

def dfs(graph,start,state,discover,finish):

    state[start-1] = 1
    global time
    time = time + 1
    discover[start-1] = time
    # print str(time) + " go to " + str(start)

    neighbours = sorted(graph[start])

    for neighbour in neighbours:
        if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

    state[start-1] = 2
    time = time + 1
    finish[start - 1] = time
    # print str(time) + " out of " + str(start)

def main():
    # g = {1: [2, 3],
    #      2: [3, 4],
    #      3: [5],
    #                     4: [6],
    #                     5: [6],
    #                     6: []}



    # deal with input
    n = int(stdin.readline())

    g = {}

    d = [0]*n
    f = [0]*n

    all_vertex = []

    for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        g[i+1] = entry
        all_vertex.append(i+1)



    # exp = []
    # state represent vertex visited state: 0 not visited 1 visiting 2 finished
    state = [0]*n

    for node in all_vertex:
        if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
    for i in xrange(n):
        print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i])

main() from sys import stdin global time time = 0 time 0 def dfs(graph,start,state,discover,finish):

    state[start-1] = 1
    global time
    time = time + 1
    discover[start-1] = time
    # print str(time) + " go to " + str(start)

    neighbours = sorted(graph[start])

    for neighbour in neighbours:
        if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

    state[start-1] = 2
    time = time + 1
    finish[start - 1] = time
    # print str(time) + " out of " + str(start) dfs state[start-1] = 1 state[start-1] state start-1 start 1 1 global time time = time + 1 time time + 1 time 1 discover[start-1] = time discover[start-1] discover start-1 start 1 time neighbours = sorted(graph[start]) neighbours sorted(graph[start]) sorted graph[start] graph start for neighbour in neighbours:
        if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

     neighbour neighbours if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

     state[neighbour-1] == 0 state[neighbour-1] state neighbour-1 neighbour 1 0 dfs(graph,neighbour,state,discover,finish) dfs graph neighbour state discover finish state[start-1] = 2 state[start-1] state start-1 start 1 2 time = time + 1 time time + 1 time 1 finish[start - 1] = time finish[start - 1] finish start - 1 start 1 time graph graph start start state state discover discover finish finish def main():
    # g = {1: [2, 3],
    #      2: [3, 4],
    #      3: [5],
    #                     4: [6],
    #                     5: [6],
    #                     6: []}



    # deal with input
    n = int(stdin.readline())

    g = {}

    d = [0]*n
    f = [0]*n

    all_vertex = []

    for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        g[i+1] = entry
        all_vertex.append(i+1)



    # exp = []
    # state represent vertex visited state: 0 not visited 1 visiting 2 finished
    state = [0]*n

    for node in all_vertex:
        if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
    for i in xrange(n):
        print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) main n = int(stdin.readline()) n int(stdin.readline()) int stdin.readline() stdin.readline stdin readline g = {} g {} d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n all_vertex = [] all_vertex [] for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        g[i+1] = entry
        all_vertex.append(i+1)



    # exp = []
    # state represent vertex visited state: 0 not visited 1 visiting 2 finished
     i xrange(n) xrange n int(s) for s in stdin.readline().split()[2:] for s in stdin.readline().split()[2:] s stdin.readline().split()[2:] stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split 2: 2 for s in stdin.readline().split()[2:] int(s) int s entry = [int(s) for s in stdin.readline().split()[2:]] entry [int(s) for s in stdin.readline().split()[2:]] g[i+1] = entry g[i+1] g i+1 i 1 entry all_vertex.append(i+1) all_vertex.append all_vertex append i+1 i 1 state = [0]*n state [0]*n [0] 0 n for node in all_vertex:
        if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
     node all_vertex if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
     state[node-1] == 0 state[node-1] state node-1 node 1 0 dfs(g,node,state,d,f) dfs g node state d f for i in xrange(n):
        print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) i xrange(n) xrange n print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) str(i+1) + ' ' + str(d[i]) + ' ' str(i+1) + ' ' + str(d[i]) str(i+1) + ' ' str(i+1) str i+1 i 1 ' ' str(d[i]) str d[i] d i ' ' str(f[i]) str f[i] f i main() main time = 0 0 time def main():
    # g = {1: [2, 3],
    #      2: [3, 4],
    #      3: [5],
    #                     4: [6],
    #                     5: [6],
    #                     6: []}



    # deal with input
    n = int(stdin.readline())

    g = {}

    d = [0]*n
    f = [0]*n

    all_vertex = []

    for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        g[i+1] = entry
        all_vertex.append(i+1)



    # exp = []
    # state represent vertex visited state: 0 not visited 1 visiting 2 finished
    state = [0]*n

    for node in all_vertex:
        if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
    for i in xrange(n):
        print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) def main():
    # g = {1: [2, 3],
    #      2: [3, 4],
    #      3: [5],
    #                     4: [6],
    #                     5: [6],
    #                     6: []}



    # deal with input
    n = int(stdin.readline())

    g = {}

    d = [0]*n
    f = [0]*n

    all_vertex = []

    for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        g[i+1] = entry
        all_vertex.append(i+1)



    # exp = []
    # state represent vertex visited state: 0 not visited 1 visiting 2 finished
    state = [0]*n

    for node in all_vertex:
        if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
    for i in xrange(n):
        print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) main global time def dfs(graph,start,state,discover,finish):

    state[start-1] = 1
    global time
    time = time + 1
    discover[start-1] = time
    # print str(time) + " go to " + str(start)

    neighbours = sorted(graph[start])

    for neighbour in neighbours:
        if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

    state[start-1] = 2
    time = time + 1
    finish[start - 1] = time
    # print str(time) + " out of " + str(start) def dfs(graph,start,state,discover,finish):

    state[start-1] = 1
    global time
    time = time + 1
    discover[start-1] = time
    # print str(time) + " go to " + str(start)

    neighbours = sorted(graph[start])

    for neighbour in neighbours:
        if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

    state[start-1] = 2
    time = time + 1
    finish[start - 1] = time
    # print str(time) + " out of " + str(start) dfs
from sys import stdin

global time
time = 0

def dfs(graph,start,state,discover,finish):

    state[start-1] = 1
    global time
    time = time + 1
    discover[start-1] = time
    # print str(time) + " go to " + str(start)

    neighbours = sorted(graph[start])

    for neighbour in neighbours:
        if state[neighbour-1] == 0:
            dfs(graph,neighbour,state,discover,finish)

    state[start-1] = 2
    time = time + 1
    finish[start - 1] = time
    # print str(time) + " out of " + str(start)

def main():
    # g = {1: [2, 3],
    #      2: [3, 4],
    #      3: [5],
    #                     4: [6],
    #                     5: [6],
    #                     6: []}



    # deal with input
    n = int(stdin.readline())

    g = {}

    d = [0]*n
    f = [0]*n

    all_vertex = []

    for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        g[i+1] = entry
        all_vertex.append(i+1)



    # exp = []
    # state represent vertex visited state: 0 not visited 1 visiting 2 finished
    state = [0]*n

    for node in all_vertex:
        if state[node-1] == 0:
            dfs(g,node,state,d,f)

    # print  'state ' + str(state)

    # print 'd' + str(d)
    # print 'f' + str(f)

    # deal with output
    for i in xrange(n):
        print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i])

main()
