题意:给定一个数n(是二的幂),然后我们把从0~n-1一对一对分,使分出来的每一对的按位与和加起来等于m,如果构造不出来输出-1,能的话输出构造的组
思路:我们能发现对于任意一个数i,他和n-1-i按位与之后是0
然后对于n-1来说,与任意一个数i能得到i
对于0来说,与任意一个数是0
我们能发现当m!=n-1的时候,我们能用m&n-1直接得出来m
然后将本来与m相匹配的n-1-m和本来与n-1匹配的0匹配
然后剩下的数i分别与n-1-i匹配即可
如果当m==n-1的时候
我们不能保证一步能创造出来m
我们可以拿n-1和n-2创造出来m-1,
然后再拿n-3和1创造出来1
然后原来和n-1匹配的0和2匹配
就能得出来m了
但是有一种特殊情况是当n==4,m==3的时候,n-3和1相等,不能匹配,所以直接输出-1了
代码如下啦
/*
.----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. |
| | ________ | || | _________ | || | ____ ____ | || | ____ | |
| | |_ ___ `. | || | |_ ___ | | || ||_ \ / _|| || | .' `. | |
| | | | `. \ | || | | |_ \_| | || | | \/ | | || | / .--. \ | |
| | | | | | | || | | _| _ | || | | |\ /| | | || | | | | | | |
| | _| |___.' / | || | _| |___/ | | || | _| |_\/_| |_ | || | \ `--' / | |
| | |________.' | || | |_________| | || ||_____||_____|| || | `.____.' | |
| | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------'
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int gcd(int a,int b){
return b>0 ? gcd(b,a%b):a;
}
/*
int dx[8]={-2,-2,-1,1,2,2,-1,1};
int dy[8]={-1,1,2,2,1,-1,-2,-2};
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
*/
const int N=1e3+10;
int n,m;
int a[N],f[N];
void sove(){
cin>>n>>m;
if(n==4&&m==3){
cout<<-1<<endl;
return ;
}
if(m==0){
int op=n/2;
for(int i=op;i<=n-1;i++)
cout<<i<<" "<<n-1-i<<endl;
return ;
}
if(m!=n-1){
cout<<m<<" "<<n-1<<endl;
cout<<0<<" "<<n-1-m<<endl;
for(int i=n/2;i<=n-2;i++){
if(i!=m&&i!=n-1-m){
cout<<i<<" "<<n-1-i<<endl;
}
}
}else{
cout<<n-1<<" "<<n-2<<endl;
cout<<n-3<<" "<<1<<endl;
cout<<0<<" "<<2<<endl;
for(int i=n/2;i<=n-4;i++){
cout<<i<<" "<<n-1-i<<endl;
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie() ,cout.tie() ;
int t=1;
cin>>t;
while(t--){
sove();
}
return 0;
}