#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k;
        scanf("%d%d",&n,&k);
        int l=k/2-(1-k%2),i;
        if(n-l-1>0)
        {
            printf("%d\n",n-l-1);
            for(i=n;i>k;i--)
            printf("%d ",i);
            for(i=k-1;i>l;i--)
            printf("%d ",i);
            printf("\n");
        }
        else printf("0\n");
    }
    return 0;
}