#include using namespace std; using uint = unsigned int; using ll = long long; ll solve() { uint L, R; cin >> L >> R; if (L == 0 and R == 0) { return 0; } int log_l = (int)bit_width(L) - 1, log_r = (int)bit_width(R) - 1; if (log_l < log_r) { return (1LL << log_r) * ((1LL << log_r) - 1); } else { return -1; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; for (int _ = 0; _ < T; _++) { cout << solve() << '\n'; } }