#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, i, j, n, m, l, r, x, y, ans;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    ans = n;
    for (i = 0; n <= m; i++) {
      if (((n >> i) & 1) == 0) n |= (1ll << i);
      if (n <= m) ans = n;
    }
    cout << ans << "\n";
  }
  return 0;
}
