#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    long long l, r;
    cin >> l >> r;
    long long low = l;
    for (int i = 0; i < 60; i++) {
      if (!(low >> i & 1) && low + (1LL << i) <= r) {
        low += 1LL << i;
      }
    }
    cout << low << "\n";
  }
  return 0;
}
