#include <bits/stdc++.h>
using namespace std;
int a[66], b[66];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    long long l, r;
    cin >> l >> r;
    int ac = 0, bc = 0;
    while (l) {
      a[ac++] = l % 2;
      l /= 2;
    }
    while (r) {
      b[bc++] = r % 2;
      r /= 2;
    }
    reverse(a, a + ac);
    reverse(b, b + bc);
    bool ao = true;
    for (int i = 0; i < bc; ++i) {
      if (b[i] == 0) ao = false;
    }
    if (ao) {
      long long ans = 0;
      for (int i = 0; i < bc; ++i) ans = ans * 2 + 1;
      cout << ans << endl;
      continue;
    }
    if (bc > ac) {
      long long ans = 0;
      for (int i = 1; i < bc; ++i) {
        ans = ans * 2 + 1;
      }
      cout << ans << endl;
      continue;
    }
    long long ans = 0;
    for (int i = 0; i < ac; ++i) {
      if (a[i] < b[i]) {
        ao = true;
        for (int j = i; j < ac; ++j)
          if (!b[j]) ao = false;
        ans = ans * 2;
        if (ao) ans++;
        for (int j = i + 1; j < ac; ++j) ans = ans * 2 + 1;
        break;
      }
      ans = ans * 2 + a[i];
    }
    cout << ans << endl;
  }
  return 0;
}
