if __name__ == '__main__':
    n = int(input())
    graph = [[0 for i in range(n)] for _ in range(n)]
    frist = [0 for _ in range(n)]
    end = [0 for _ in range(n)]
    visit = [False for _ in range(n)]
    # get the group
    for i in range(n):
        datas = [int(num) for num in input().split(' ')]
        if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

    visit[0] = True
    frist[0] = s = 1
    stack = [0]

    while len(stack) != 0:
        point = stack.pop(-1)
        flag = False
        for i in range(n):
            if graph[point][i] == 1 and visit[i] is False:
                visit[i] = True
                flag = True
                s += 1
                frist[i] = s
                stack.append(point)
                stack.append(i)
                break
        if flag is False:
            s += 1
            end[point] = s
        
        if len(stack) == 0:
            for i in range(n):
                if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
    for i in range(n):
        print('%d %d %d' % (i+1, frist[i], end[i])) if __name__ == '__main__':
    n = int(input())
    graph = [[0 for i in range(n)] for _ in range(n)]
    frist = [0 for _ in range(n)]
    end = [0 for _ in range(n)]
    visit = [False for _ in range(n)]
    # get the group
    for i in range(n):
        datas = [int(num) for num in input().split(' ')]
        if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

    visit[0] = True
    frist[0] = s = 1
    stack = [0]

    while len(stack) != 0:
        point = stack.pop(-1)
        flag = False
        for i in range(n):
            if graph[point][i] == 1 and visit[i] is False:
                visit[i] = True
                flag = True
                s += 1
                frist[i] = s
                stack.append(point)
                stack.append(i)
                break
        if flag is False:
            s += 1
            end[point] = s
        
        if len(stack) == 0:
            for i in range(n):
                if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
    for i in range(n):
        print('%d %d %d' % (i+1, frist[i], end[i])) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input [0 for i in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for i in range(n)] graph = [[0 for i in range(n)] for _ in range(n)] graph [[0 for i in range(n)] for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 frist = [0 for _ in range(n)] frist [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 end = [0 for _ in range(n)] end [0 for _ in range(n)] False for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) False visit = [False for _ in range(n)] visit [False for _ in range(n)] for i in range(n):
        datas = [int(num) for num in input().split(' ')]
        if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

     i range(n) range n int(num) for num in input().split(' ') for num in input().split(' ') num input().split(' ') ().split () input split ' ' for num in input().split(' ') int(num) int num datas = [int(num) for num in input().split(' ')] datas [int(num) for num in input().split(' ')] if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

     datas[1] > 0 datas[1] datas 1 0 for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

     j datas[2:] datas 2: 2 graph[datas[0] - 1][j - 1] = 1 graph[datas[0] - 1][j - 1] [datas[0] - 1] graph datas[0] - 1 datas[0] datas 0 1 j - 1 j 1 1 visit[0] = True visit[0] visit 0 True frist[0] = s = 1 frist[0] frist 0 1 = s = 1 s 1 stack = [0] stack [0] 0 while len(stack) != 0:
        point = stack.pop(-1)
        flag = False
        for i in range(n):
            if graph[point][i] == 1 and visit[i] is False:
                visit[i] = True
                flag = True
                s += 1
                frist[i] = s
                stack.append(point)
                stack.append(i)
                break
        if flag is False:
            s += 1
            end[point] = s
        
        if len(stack) == 0:
            for i in range(n):
                if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
     len(stack) != 0 len(stack) len stack 0 point = stack.pop(-1) point stack.pop(-1) stack.pop stack pop -1 flag = False flag False for i in range(n):
            if graph[point][i] == 1 and visit[i] is False:
                visit[i] = True
                flag = True
                s += 1
                frist[i] = s
                stack.append(point)
                stack.append(i)
                break
         i range(n) range n if graph[point][i] == 1 and visit[i] is False:
                visit[i] = True
                flag = True
                s += 1
                frist[i] = s
                stack.append(point)
                stack.append(i)
                break
         graph[point][i] == 1 and visit[i] is False graph[point][i] == 1 graph[point][i] [point] graph point i 1 visit[i] is False visit[i] visit i False visit[i] = True visit[i] visit i True flag = True flag True s += 1 s 1 frist[i] = s frist[i] frist i s stack.append(point) stack.append stack append point stack.append(i) stack.append stack append i break if flag is False:
            s += 1
            end[point] = s
        
         flag is False flag False s += 1 s 1 end[point] = s end[point] end point s if len(stack) == 0:
            for i in range(n):
                if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
     len(stack) == 0 len(stack) len stack 0 for i in range(n):
                if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
     i range(n) range n if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
     visit[i] is False visit[i] visit i False visit[i] = True visit[i] visit i True s += 1 s 1 frist[i] = s frist[i] frist i s stack.append(i) stack.append stack append i break for i in range(n):
        print('%d %d %d' % (i+1, frist[i], end[i])) i range(n) range n print('%d %d %d' % (i+1, frist[i], end[i])) print '%d %d %d' % (i+1, frist[i], end[i]) '%d %d %d' (i+1, frist[i], end[i]) i+1 i 1 frist[i] frist i end[i] end i s += 1 1 s visit = [False for _ in range(n)] [False for _ in range(n)] visit s += 1 1 s s += 1 1 s graph = [[0 for i in range(n)] for _ in range(n)] [[0 for i in range(n)] for _ in range(n)] graph flag = True True flag s = 1 1 s frist = [0 for _ in range(n)] [0 for _ in range(n)] frist end = [0 for _ in range(n)] [0 for _ in range(n)] end datas = [int(num) for num in input().split(' ')] [int(num) for num in input().split(' ')] datas stack = [0] [0] stack point = stack.pop(-1) stack.pop(-1) point n = int(input()) int(input()) n flag = False False flag
if __name__ == '__main__':
    n = int(input())
    graph = [[0 for i in range(n)] for _ in range(n)]
    frist = [0 for _ in range(n)]
    end = [0 for _ in range(n)]
    visit = [False for _ in range(n)]
    # get the group
    for i in range(n):
        datas = [int(num) for num in input().split(' ')]
        if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

    visit[0] = True
    frist[0] = s = 1
    stack = [0]

    while len(stack) != 0:
        point = stack.pop(-1)
        flag = False
        for i in range(n):
            if graph[point][i] == 1 and visit[i] is False:
                visit[i] = True
                flag = True
                s += 1
                frist[i] = s
                stack.append(point)
                stack.append(i)
                break
        if flag is False:
            s += 1
            end[point] = s
        
        if len(stack) == 0:
            for i in range(n):
                if visit[i] is False:
                    visit[i] = True
                    s += 1
                    frist[i] = s
                    stack.append(i)
                    break
            
    for i in range(n):
        print('%d %d %d' % (i+1, frist[i], end[i]))
