Under construction

Still being built. Things may change

Permutations and Cycles (Minimum Version)

Time limit2sMemory limit2048 MB

Summary
Given n and x, build a permutation of 1 to n where each adjacent pair sums to at most x, using the fewest cycles.
Level

Medium5 of 10

Topics
Array, Greedy, Implementation
Solved
No attempts yet

Problem

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

A permutation of size nn is a sequence of nn distinct integers from 11 to nn.

A cycle of a permutation pp is a sequence of indices i1,i2,…,iki_1, i_2, \ldots, i_k such that pi1=i2p_{i_1} = i_2, pi2=i3p_{i_2} = i_3, …\ldots, pik=i1p_{i_k} = i_1. Cycles that differ only by a cyclic shift of the sequence are considered the same.

Input

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

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

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, print two lines. The first line contains the minimum number of cycles in a good permutation of length nn. The second line contains the nn integers of the permutation. If multiple such permutations exist, print any one of them.

Examples1

  1. Example 1

    Input
    2
    2 3
    6 10
    
    Expected output
    1
    2 1
    1
    5 4 6 3 2 1