#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        
        if((k%4)==0) cout<<"NO"<<endl;
        else if((k%4)==1||(k%4)==3){
            cout<<"YES"<<endl;
            for(int i=1;i<n;i=i+2){
                cout<<i<<" "<<i+1<<endl;
            }
        }
        else{
            cout<<"YES"<<endl;
            for(int i=1;i<n;i=i+2){
               if((i+1)%4==0){
                   cout<<i<<" "<<i+1<<endl;
               }
               else{
                   cout<<i+1<<" "<<i<<endl;
               }
            }
        }
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: