Permutations and Cycles (Minimum Version)

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

문제

For a given $x$, a permutation of size $n$ is called good if for each $1 \le i < n$ the condition $p_i + p_{i + 1} \le x$ holds. Find any good permutation with the minimum number of cycles.

A permutation of size $n$ is a sequence of $n$ distinct integers from $1$ to $n$.

A cycle of a permutation $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $p_{i_1} = i_2$, $p_{i_2} = i_3$, $\ldots$, $p_{i_k} = i_1$. The cycles obtained by a cyclic shifting of the sequence are considered to be the same.

입력

The first line contains an integer $t$ ($1 \le t \le 2 \cdot 10^5$), the number of test cases. The test cases follow.

Each test case is given on a line with two integers $n$ ($2 \le n \le 2 \cdot 10^5$) and $x$ ($n + 1 \le x \le 2 \cdot n - 1$). These constraints guarantee that at least one good permutation exists.

The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

출력

For each test case, print two lines. The first one should contain the minimum number of cycles in a good permutation of length $n$. The second line should consist of $n$ integers: the permutation itself. If multiple such permutations exist, print any one of them.