#include #include #include #include #include #include #include #include #include #include #define ll long long #define db double using namespace std; ll tt,x,y; void solve() { scanf("%lld%lld",&y,&x); ll val = 1; while(x > 0) { x--; val *= 2; } while(true) { if (y & (val * 2)) { val *= 2; } else { break; } } printf("%lld\n",2 * val - 1); } int main() { scanf("%lld",&tt); while(tt) { solve(); tt--; } return 0; }