#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
// Precompute step sizes S[1..30]
vector<ll> S;
S.push_back(0); // S[0] unused
S.push_back(2); // S[1]=2
for(int k=2; k<=30; ++k){
S.push_back(2*S[k-1] +1);
}
int Q;
cin >> Q;
while(Q--){
ll x, y;
cin >> x >> y;
// Find smallest k where S[k] >=x
int k=1;
for(; k<=30; ++k){
if(S[k] >=x){
break;
}
}
if(k >30){
// Should not happen as S[30] ~1.6e9 >=1e9
cout << "1\n";
continue;
}
if(k ==1){
// Step1: all red
cout << "1\n";
continue;
}
ll S_prev = S[k-1];
ll y_center = S_prev +1;
ll x_prime = x - S_prev;
// Check if |y - y_center| <= S_prev +1 -x_prime
ll diff = abs(y - y_center);
ll limit = S_prev +1 - x_prime;
if(diff <= limit){
cout << "0\n";
}
else{
cout << "1\n";
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmludCBtYWluKCl7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKDApOwogICAgLy8gUHJlY29tcHV0ZSBzdGVwIHNpemVzIFNbMS4uMzBdCiAgICB2ZWN0b3I8bGw+IFM7CiAgICBTLnB1c2hfYmFjaygwKTsgLy8gU1swXSB1bnVzZWQKICAgIFMucHVzaF9iYWNrKDIpOyAvLyBTWzFdPTIKICAgIGZvcihpbnQgaz0yOyBrPD0zMDsgKytrKXsKICAgICAgICBTLnB1c2hfYmFjaygyKlNbay0xXSArMSk7CiAgICB9CiAgICBpbnQgUTsKICAgIGNpbiA+PiBROwogICAgd2hpbGUoUS0tKXsKICAgICAgICBsbCB4LCB5OwogICAgICAgIGNpbiA+PiB4ID4+IHk7CiAgICAgICAgLy8gRmluZCBzbWFsbGVzdCBrIHdoZXJlIFNba10gPj14CiAgICAgICAgaW50IGs9MTsKICAgICAgICBmb3IoOyBrPD0zMDsgKytrKXsKICAgICAgICAgICAgaWYoU1trXSA+PXgpewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoayA+MzApewogICAgICAgICAgICAvLyBTaG91bGQgbm90IGhhcHBlbiBhcyBTWzMwXSB+MS42ZTkgPj0xZTkKICAgICAgICAgICAgY291dCA8PCAiMVxuIjsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGlmKGsgPT0xKXsKICAgICAgICAgICAgLy8gU3RlcDE6IGFsbCByZWQKICAgICAgICAgICAgY291dCA8PCAiMVxuIjsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGxsIFNfcHJldiA9IFNbay0xXTsKICAgICAgICBsbCB5X2NlbnRlciA9IFNfcHJldiArMTsKICAgICAgICBsbCB4X3ByaW1lID0geCAtIFNfcHJldjsKICAgICAgICAvLyBDaGVjayBpZiB8eSAtIHlfY2VudGVyfCA8PSBTX3ByZXYgKzEgLXhfcHJpbWUKICAgICAgICBsbCBkaWZmID0gYWJzKHkgLSB5X2NlbnRlcik7CiAgICAgICAgbGwgbGltaXQgPSBTX3ByZXYgKzEgLSB4X3ByaW1lOwogICAgICAgIGlmKGRpZmYgPD0gbGltaXQpewogICAgICAgICAgICBjb3V0IDw8ICIwXG4iOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICBjb3V0IDw8ICIxXG4iOwogICAgICAgIH0KICAgIH0KfQo=