#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { ll L, R; cin >> L >> R; if (R == 0) { cout << "0\n"; } else if (L > 0 && bit_width((unsigned)L) == bit_width((unsigned)R)) { cout << "-1\n"; } else { int k = bit_width((unsigned)R) - 1; cout << (1LL << k) * ((1LL << k) - 1) << '\n'; } } }