#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; void solve() { ll x, y; cin >> x >> y; ll t = ((x + (1LL << y)) >> y) << y; for (int i = 0; i < 62; i++) { if (t & (1 << i)) { cout << (1 << i) - 1 << endl; break; } } } int main() { int T; cin >> T; while (T--) { solve(); } return 0; }