#include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i,n) for (int i = 0; i < int(n);i++) int main(){ int tt; cin >> tt; while(tt--){ ll x; int y; cin >> x >> y; int yy = y; for (int i = y+1; i < 60;i++){ if (x & (1LL << i)){ yy++; } else{ break; } } cout << (1LL << yy+1)-1LL << endl; } return 0; }