#include <bits/stdc++.h>
int DBG = 0;
using namespace std;
const int MAXN = 10005;
int n;
char l[100], r[100], ans[100];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    long long a, b;
    scanf("%I64d%I64d", &a, &b);
    ++b;
    for (int i = 0; i < 64; ++i) l[i] = (a & (1LL << i)) ? '1' : '0';
    for (int i = 0; i < 64; ++i) r[i] = (b & (1LL << i)) ? '1' : '0';
    int p;
    for (p = 63; p >= 0 && l[p] == r[p]; --p) ans[p] = l[p];
    ans[p] = '0';
    for (int i = p - 1; i >= 0; --i) ans[i] = '1';
    long long res = 0;
    for (int i = 0; i < 64; ++i)
      if (ans[i] == '1') res |= 1LL << i;
    printf("%I64d\n", res);
  }
}
