#include using namespace std; using ll = long long; template using min_priority_queue = priority_queue, greater>; using pii = pair; using pll = pair; using Graph = vector>; const ll INF = 1LL << 60; template void chmax(T& a, T b) { if (b > a) a = b; } template void chmin(T& a, T b) { if (b < a) a = b; } template std::ostream& operator<<(std::ostream& os, const pair& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template void print_vector(vector a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } void solve() { ll x, y; cin >> x >> y; ll r = y; while (true) { if (!((x >> r) & 1)) break; r++; } // std::cout << r << "\n"; std::cout << (1LL << r) - 1 << "\n"; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int T; cin >> T; while (T--) { solve(); } return 0; }