Permutations and Cycles (Maximum Version)
시간 제한2초메모리 제한2048 MB
인접한 두 값의 합이 x 이하가 되는 순열 가운데 사이클 수가 최대인 순열을 각 테스트마다 하나씩 구한다.
문제
For a given , a permutation of size is called good if for each the condition holds. Find any good permutation with the maximum number of cycles.
A permutation of size is a sequence of distinct integers from to .
A cycle of a permutation is a sequence of indices such that , , , . The cycles obtained by a cyclic shifting of the sequence are considered to be the same.
입력
The first line contains an integer (), the number of test cases. The test cases follow.
Each test case is given on a line with two integers () and (). These constraints guarantee that at least one good permutation exists.
The sum of over all test cases does not exceed .
출력
For each test case, print two lines. The first one should contain the maximum number of cycles in a good permutation of length . The second line should consist of integers: the permutation itself. If multiple such permutations exist, print any one of them.