#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, l, r, res, i, j, a, b;
  scanf("%I64d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d %I64d", &l, &r);
    res = l;
    a = (long long int)log2(r) + 1;
    for (j = 0; j < a; j++) {
      b = ((long long int)1 << (long long int)j);
      if (!(res & b)) {
        if (res + b <= r)
          res = res + b;
        else
          break;
      }
    }
    printf("%I64d\n", res);
  }
  return 0;
}
