RT,赛事稀里糊涂就过了……个人感觉很玄学……
#include <iostream>
#define int long long
using namespace std;
int t,n,x;
int in_it[63];
void init(){
in_it[0]=1;
for(int i=1;i<=62;i++) in_it[i]=in_it[i-1]*2;
}
bool work(){
bool c[66];
int cnt=-1,tn=n;
while(tn){
c[++cnt]=tn%2;
tn/=2;
}
tn=n;
for(int i=0;i<=cnt;i++){
if(c[i]){
tn-=in_it[i];
if(tn==x) return true;
}
}
return false;
}
signed main(){
init();
cin>>t;
while(t--){
cin>>n>>x;
if(n<x){
cout<<"-1\n";
continue;
}
if(n==x){
cout<<n<<endl;
continue;
}
if((n|x)!=n){
cout<<"-1\n";
continue;
}
if(!work()){
cout<<"-1\n";
continue;
}
int tmp=n^x;
for(int i=0;;i++){
if(in_it[i]>tmp){
if(((n+in_it[i]-tmp)&n)!=x) cout<<"-1\n";
else cout<<n+in_it[i]-tmp<<endl;
break;
}
}
}
return 0;
}