#include <bits/stdc++.h>
#define mis(x) cout << #x <<" = " <<x<<endl
#define rep(i, a, b) for(int i=(a);(i)<(b);(i)++)
#define re(i,a) rep((i),0,(a))
#define eb emplace_back
#define x first
#define y second
	//	#define cin fin
using namespace std;
typedef long long ll;
ifstream fin("Sisend.txt");
ll t,n,k;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);	cout.tie(0);cerr.tie(0);
	cin>>t;while(t--){
		cin>>n>>k;
		ll vas=0;
		if(n>k)vas+=n-k;
		vas+=k/2;
		cout<<vas<<endl;
		if(k<n)for(int i=k+1;i<=n;i++)cout<<i<<" ";
		for(int i=k/2+k%2;i<k;i++)cout<<i<<" ";
		cout<<endl;
	}
}

