#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll x, y, ans = 0; cin >> x >> y; ll c = y; while(x >> c & 1){ ans += 1ll << c; c++; } c = y - 1; while(c >= 0){ ans += 1ll << c; c--; } cout << ans << '\n'; } }