#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
double tick() {
  static clock_t oldt;
  clock_t newt = clock();
  double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
  oldt = newt;
  return diff;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin.ignore(0);
  long long n;
  cin >> n;
  while (n--) {
    long long l, r;
    cin >> l >> r;
    for (long long j = 1; l + j <= r; j <<= 1) {
      if ((l & j) == 0) l += j;
    }
    cout << l << endl;
  }
}
