#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long l, r, s = 0;
    bool ok;
    int count = 0;
    cin >> l >> r;
    long long l1 = log2((double)l) + 1;
    long long l2 = log2((double)r) + 1;
    if (((long long)1 << l2) - 1 == r)
      s = r;
    else if (l1 != l2) {
      s = ((long long)1 << (l2 - 1)) - 1;
    } else {
      while (((l >> l2) & 1) == ((r >> l2) & 1) && l2 != -1) l2--;
      --l2;
      if (l2 == -1)
        s = r;
      else {
        if (l2 >= 0) {
          l = (l >> (l2 + 1) << (l2 + 1));
          if (r == (l + ((long long)1 << (l2 + 2)) - 1))
            l = r;
          else {
            l += (((long long)1 << (l2 + 1)) - 1);
          }
        }
        s = l;
      }
    }
    cout << s << "\n";
  }
}
