#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long a, b;
    scanf("%I64d %I64d", &a, &b);
    for (long long d = 1; d + a <= b; d *= 2)
      if (!(d & a)) a += d;
    printf("%I64d\n", a);
  }
}
