#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define F first
#define S second
#define pb push_back
#define lg2(x) 31-__builtin_clz(x)
#define lg(x,b) log(b)/log(x)

int t,n,k,a,ans;

int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

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

return 0;
}
