#include <bits/stdc++.h>
inline long long read() {
  long long ans = 0;
  char ch = getchar(), t = ch;
  while (ch < '0' || ch > '9') {
    t = ch;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ans = ans * 10 + ch - '0';
    ch = getchar();
  }
  if (t == '-') ans = -ans;
  return ans;
}
inline int readd() {
  int ans = 0;
  char ch = getchar(), t = ch;
  while (ch < '0' || ch > '9') {
    t = ch;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ans = ans * 10 + ch - '0';
    ch = getchar();
  }
  if (t == '-') ans = -ans;
  return ans;
}
int main() {
  int _ = readd();
  while (_--) {
    long long l = read(), r = read();
    if (l == 0 && r == 0) {
      printf("0\n");
      continue;
    }
    int bit = 0;
    long long mid = 1, m;
    while (mid <= r) {
      m = l | mid;
      if (m > r) {
        printf("%I64d\n", l);
        break;
      }
      l = m;
      if (l == r) {
        printf("%I64d\n", l);
        break;
      }
      bit++;
      mid = (1ll * 1 << bit);
    }
  }
  return 0;
}
