#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long l, r;
    cin >> l >> r;
    long long ans = 0;
    int x = 0;
    while ((r >> x) & 1) {
      x++;
      if (x == 60) break;
    }
    int y = 60;
    while (((r >> y) & 1) == ((l >> y) & 1)) {
      y--;
      if (!y) break;
    }
    for (int j = 60; j > y; j--)
      if ((r >> j) & 1ll) ans += (1ll << j);
    if (y < x)
      ans += (1ll << (y + 1)) - 1;
    else
      ans += (1ll << y) - 1;
    cout << ans << endl;
  }
  return 0;
}
