#include <bits/stdc++.h>
long long int n, a, b;
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &a, &b);
    long long int k;
    k = a;
    for (int i = 0; i < 60; i++) {
      if ((k | (1ll << i)) <= b)
        k |= 1ll << i;
      else if ((k | 1ll << i) > b)
        break;
    }
    printf("%I64d\n", k);
  }
  return 0;
}
