#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T M) {
  long long int ret = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1) ret = (ret * b) % M;
    b = (b * b) % M;
  }
  return (T)ret;
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  return a * b / gcd<T>(a, b);
}
template <class T>
inline T power(T b, T p) {
  long long int x = 1;
  while (p--) x *= b;
  return x;
}
const long long int mod = 1e9 + 7;
const int siz = 202;
string toBinary(long long int n) {
  string ret;
  while (n) {
    if (n % 2 == 1)
      ret += '1';
    else
      ret += '0';
    n /= 2;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long int l, r;
    cin >> l >> r;
    long long int sum = l, k = 1;
    string bin = toBinary(l);
    for (int i = bin.size() - 1; i >= 0; i--, k *= 2) {
      if (bin[i] == '0' && sum + k <= r) sum += k;
    }
    while (sum + k <= r) sum += k, k *= 2;
    cout << sum << endl;
  }
  return 0;
}
