아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Hamilton

시간 제한2초메모리 제한512 MB

요약
1부터 n까지 모든 칸을 정확히 한 번씩 방문하면서 a에서 b로 이동할 때, gcd가 1인 칸으로만 건너뛸 수 있는 비행을 최소 몇 번 해야 하는지 구하고 그 경로를 출력한다.
난이도

보통10점 중 5점

유형
그래프, 정수론, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Lin-Manuel is moving along a strip consisting of nn cells consecutively numbered from 1 to nn.

He starts at cell aa and want to finish at cell bb. In the process, he wants to visit every cell exactly once.

From any cell xx, Lin-Manuel can walk to the neighboring cell on the left, cell x−1x - 1 (if it exists), or on the right, cell x+1x + 1 (if it exists).

He can also call for his friend, witch Miranda, who will grant him a magic power. With this power, he will be able to fly exactly once from his current cell xx to any cell yy such that the greatest common divisor of xx and yy is 1.

Lin-Manuel doesn't want to burden Miranda too much. Thus, he would like to achieve his goal flying as few times as possible.

Help him and find the smallest number of flights required along with the optimal sequence of visiting cells.

입력

The first line of the input contains a single integer tt (1≤t≤1031 \le t \le 10^3) --- the number of test cases.

Each of the next tt lines contains three integers nn, aa, and bb (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; 1≤a,b≤n1 \le a, b \le n; a≠ba \ne b) --- the number of cells on the strip, the starting cell, and the finishing cell, respectively.

The sum of all values of nn doesn't exceed 2⋅1052 \cdot 10^5.

출력

For each test case, if it's impossible to achieve the goal with any number of flights, output a single integer −1-1.

Otherwise, output the smallest number of flights required to travel from cell aa to cell bb visiting all cells exactly once, followed by nn distinct integers c_1,c_2,…,c_nc\_1, c\_2, \ldots, c\_n (1≤c_i≤n1 \le c\_i \le n) --- cell numbers in order of visiting, describing any valid path which needs the smallest possible number of flights. In particular, it must be true that c_1=ac\_1 = a and c_n=bc\_n = b.

예제1

  1. 예제 1

    입력
    4
    5 1 5
    6 4 5
    7 5 3
    4 1 3
    
    예상 출력
    0
    1 2 3 4 5
    1
    4 3 2 1 6 5
    2
    5 4 7 6 1 2 3
    -1