#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int res = 0;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar();
  return res;
}
const int N = 1000010;
int main() {
  int n = in();
  while (n--) {
    long long mn, mx;
    cin >> mn >> mx;
    long long ans = mn;
    long long cur = mn;
    while (cur <= mx) {
      ans = cur;
      cur = cur | (cur + 1);
    }
    cout << ans << endl;
  }
  return 0;
}
