#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long l, r, ans = 0, i;
    cin >> l >> r;
    bitset<62> a(l);
    while (1) {
      long long x, y;
      for (i = 0; i <= 60; i++) {
        if (a[i] == 0) {
          y = i;
          break;
        }
      }
      x = pow(2, y);
      if (l + x > r)
        break;
      else {
        l += x;
        a[y] = 1;
      }
    }
    for (i = 0; i <= 60; i++) {
      long long x = pow(2, i);
      if (a[i] == 1) ans += x;
    }
    cout << ans << endl;
  }
}
