#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { ll l, r; cin >> l >> r; ll b = 1; ll R = r; while (R != 1) { R /= 2; b *= 2; } if (l <= b - 1) { cout << (b - 1) * b << endl; } else { cout << -1 << endl; } } return 0; }