#include <bits/stdc++.h>
using namespace std;
const int maxN = 2000;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long l, r;
    cin >> l >> r;
    int ans = 0;
    long long mn = r;
    long long cur = 0;
    int cnt = 0;
    for (int i = 60; i >= 0; i--) {
      long long tmp = r;
      if (r & (1ll << i)) {
        if (cur + (1ll << i) - 1 >= l) {
          if (ans < cnt + i) {
            mn = cur + (1ll << i) - 1;
            ans = cnt + i;
          }
        }
        cnt++;
        cur += (1ll << i);
      }
    }
    if (cnt > ans) {
      ans = cnt;
      mn = r;
    }
    cout << mn << "\n";
  }
  return 0;
}
