#include using namespace std; vector c(61); void solve() { long long x; int y; cin >> x >> y; if(!(x >> y & 1)) { cout << 0 << '\n'; } else { int i = 0; while(!(x >> i & 1)) { i++; } while(x >> i & 1) { i++; } cout << c[i - 1] << '\n'; } } int main() { c[0] = 1; for(int i = 1; i < 61; i++) { c[i] = c[i - 1] + (1LL << i); } int T; cin >> T; while(T--) { solve(); } return 0; }