Hamilton
시간 제한2초메모리 제한512 MB
1부터 n까지 모든 칸을 정확히 한 번씩 방문하면서 a에서 b로 이동할 때, gcd가 1인 칸으로만 건너뛸 수 있는 비행을 최소 몇 번 해야 하는지 구하고 그 경로를 출력한다.
문제
Lin-Manuel is moving along a strip consisting of cells consecutively numbered from 1 to .
He starts at cell and want to finish at cell . In the process, he wants to visit every cell exactly once.
From any cell , Lin-Manuel can walk to the neighboring cell on the left, cell (if it exists), or on the right, cell (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 to any cell such that the greatest common divisor of and 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 () --- the number of test cases.
Each of the next lines contains three integers , , and (; ; ) --- the number of cells on the strip, the starting cell, and the finishing cell, respectively.
The sum of all values of doesn't exceed .
출력
For each test case, if it's impossible to achieve the goal with any number of flights, output a single integer .
Otherwise, output the smallest number of flights required to travel from cell to cell visiting all cells exactly once, followed by distinct integers () --- 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 and .