#include using namespace std; int main() { int T; long long x, y; cin >> T; for (int _ = 0; _ < T; _++) { cin >> x >> y; long long t = ((x + (1 << y)) >> y) << y; for (long long i = 0; i < 62; i++) { if (t & (1 << i)) { cout << (1 << i) - 1 << '\n'; break; } } } }