#include <bits/stdc++.h>
using namespace std;
const int maxbit = 64;
long long query(long long, long long);
int main() {
  int test;
  scanf("%d", &test);
  while (test) {
    long long a, b;
    scanf("%I64d %I64d", &a, &b);
    printf("%I64d\n", query(a, b));
    --test;
  }
  return 0;
}
long long query(long long a, long long b) {
  if (a == b)
    return a;
  else {
    int i;
    for (i = 63; (i); --i) {
      if (b & (1LL << i)) break;
    }
    if ((1LL << i) <= a)
      return query(a - (1LL << i), b - (1LL << i)) + (1LL << i);
    else if ((1LL << (i + 1)) - 1 <= b)
      return (1LL << (i + 1)) - 1;
    else
      return (1LL << i) - 1;
  }
}
