#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n,k;

        cin>>n>>k;

        vector<ll>arr,check(n+1,0);
        ll cnt=0;
        for(ll i=k+1;i<=n;i++){
            arr.pb(i);
            cnt++;
        }
        for(int i=k-1;i>=1;i--){
            if(check[i]==0){
                arr.pb(i);
                cnt++;
                check[k-i]=1;
            }
        }
        cout<<cnt<<endl;
        for(int i=0;i<cnt;i++){
            cout<<arr[i]<<" \n"[i==cnt-1];
        }


    }


    return 0;
}

