#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef unsigned long long ll;
typedef long double ld;
ll go(ll x, ll a, ll b, ll i) {
if ((((a*x)^b)-x)%((1 << i)) == 0) {
if (i == 64) {
return x;
}
ll y = go(x, a, b, i + 1);
if (y > 0) {
return y;
} else {
y = go(x + (1 << i), a, b, i + 1);
if (y > 0) {
return y;
} else {
return 0;
}
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int tc = 0; tc < t; tc++) {
ll a, b;
cin >> a >> b;
if (b == 0) {
cout << "0\n";
} else {
ll x = go(0, a, b, 0);
if (x == 0) {
cout << "-\n";
} else {
cout << x << "\n";
}
}
}
}