/* T = int(input()) for _ in range(T): x, y = map(int, input().split()) t = ((x + (1 << y)) >> y) << y for i in range(60): if t & (1 << i): print((1 << i) - 1) break */ #include using namespace std; int main() { int T, x, y; cin >> T; for (int _ = 0; _ < T; _++) { cin >> x >> y; int t = ((x + (1 << y)) >> y) << y; for (int i = 0; i < 60; i++) { if (t & (1 << i)) { cout << (1 << i) - 1 << '\n'; break; } } } }