#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,k,ans;
        cin>>n>>k;
        ans=n-k+(k)/2;
        cout<<ans<<"\n";
        for(int i=n;i>k;i--){
            cout<<i<<" ";
        }
        for(int i=k-1;i>=(k/2+k%2);i--){
            cout<<i<<" ";
        }
        cout<<"\n";
    }
}
