#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int t;
    cin >> t;
    while(t--){
        long long x;
        cin >> x;
        int y;
        cin >> y;
        for(int i=y+1;i<=60;++i){
            if((x>>i)%2==0){
                cout << (1LL<<i)-1 << endl;
                break;
            }
        }
    }
    return 0;
}