#include #include #include using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll calc(ll x,ll y){ int bins[65],i = 0; rep(_,65){ if (x > 0){ bins[i] = x % 2; x /= 2; i++; }else break; } while(y < i && bins[y] == 1)y++; return pow(2,y) - 1; } int main(){ int T; cin >> T; ll results[T]; rep(i,T){ ll x,y; cin >> x >> y; results[i] = calc(x,y); } rep(i,T){ cout << results[i] << endl; } }