#include <bits/stdc++.h>
const long long int mod = 1000000007;
const long long int AM = 2e5 + 5;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int l, r;
    cin >> l >> r;
    long long int tmp = l;
    for (__typeof(0) i = 0; i < 65; ++i) {
      long long int x = tmp & (1LL << i);
      if (!x) {
        if (tmp + (1LL << i) <= r)
          tmp += (1LL << i);
        else
          break;
      }
    }
    cout << tmp << '\n';
  }
}
