#include <bits/stdc++.h>
using namespace std;
unsigned long long popcount(unsigned long long value) {
  unsigned long long pos = 0;
  while (value) {
    if (value & 1) ++pos;
    value >>= 1;
  }
  return pos;
}
unsigned long long GetLowestBitPos(unsigned long long value) {
  unsigned long long pos = 0;
  while ((value & 1)) {
    value >>= 1;
    ++pos;
  }
  return pos;
}
unsigned long long setbit(unsigned long long v, unsigned long long pos) {
  return v | 1ULL << pos;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    unsigned long long l, r;
    cin >> l >> r;
    unsigned long long ans = l;
    while (true) {
      unsigned long long tmp = ans;
      bitset<64> lol(ans);
      ans = setbit(ans, GetLowestBitPos(ans));
      if (ans > r) {
        cout << tmp << endl;
        break;
      }
    }
  }
  return 0;
}
