#include using namespace std; using ll = long long; void solve() { ll x; int y; cin >> x >> y; while ((x >> y) & 1) { y ++; } cout << (1ll << y) - 1 << endl; } int main () { int T; cin >> T; while (T --) { solve(); } }