#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
bool isRed(ll x, ll y) {
// Si c'est le sommet du triangle initial
if (x == 1 && y == 1) return true;
// Trouver la plus grande puissance de 2 inférieure ou égale à x
ll step = 1;
while ((1LL << step) <= x) step++;
step--;
// Taille du sous-triangle à cette étape
ll size = (1LL << step);
// Position relative dans le sous-triangle
ll relX = x;
ll relY = y;
while (size > 1) {
// Si le point est dans le triangle du milieu (bleu)
if (relX > size/2 && relY > relX - size && relY <= relX) {
return false;
}
// Ajuster les coordonnées pour le sous-triangle approprié
if (relX > size/2) {
if (relY <= relX - size) {
// Triangle gauche
relX = relX - size/2;
} else if (relY > relX) {
// Triangle droit
relX = relX - size/2;
relY = relY - size;
}
}
size /= 2;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
while (Q--) {
ll x, y;
cin >> x >> y;
cout << (isRed(x, y) ? 1 : 0) << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdXNpbmcgbGwgPSBsb25nIGxvbmc7Cgpib29sIGlzUmVkKGxsIHgsIGxsIHkpIHsKICAgIC8vIFNpIGMnZXN0IGxlIHNvbW1ldCBkdSB0cmlhbmdsZSBpbml0aWFsCiAgICBpZiAoeCA9PSAxICYmIHkgPT0gMSkgcmV0dXJuIHRydWU7CiAgICAKICAgIC8vIFRyb3V2ZXIgbGEgcGx1cyBncmFuZGUgcHVpc3NhbmNlIGRlIDIgaW5mw6lyaWV1cmUgb3Ugw6lnYWxlIMOgIHgKICAgIGxsIHN0ZXAgPSAxOwogICAgd2hpbGUgKCgxTEwgPDwgc3RlcCkgPD0geCkgc3RlcCsrOwogICAgc3RlcC0tOwogICAgCiAgICAvLyBUYWlsbGUgZHUgc291cy10cmlhbmdsZSDDoCBjZXR0ZSDDqXRhcGUKICAgIGxsIHNpemUgPSAoMUxMIDw8IHN0ZXApOwogICAgCiAgICAvLyBQb3NpdGlvbiByZWxhdGl2ZSBkYW5zIGxlIHNvdXMtdHJpYW5nbGUKICAgIGxsIHJlbFggPSB4OwogICAgbGwgcmVsWSA9IHk7CiAgICAKICAgIHdoaWxlIChzaXplID4gMSkgewogICAgICAgIC8vIFNpIGxlIHBvaW50IGVzdCBkYW5zIGxlIHRyaWFuZ2xlIGR1IG1pbGlldSAoYmxldSkKICAgICAgICBpZiAocmVsWCA+IHNpemUvMiAmJiByZWxZID4gcmVsWCAtIHNpemUgJiYgcmVsWSA8PSByZWxYKSB7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgLy8gQWp1c3RlciBsZXMgY29vcmRvbm7DqWVzIHBvdXIgbGUgc291cy10cmlhbmdsZSBhcHByb3ByacOpCiAgICAgICAgaWYgKHJlbFggPiBzaXplLzIpIHsKICAgICAgICAgICAgaWYgKHJlbFkgPD0gcmVsWCAtIHNpemUpIHsKICAgICAgICAgICAgICAgIC8vIFRyaWFuZ2xlIGdhdWNoZQogICAgICAgICAgICAgICAgcmVsWCA9IHJlbFggLSBzaXplLzI7CiAgICAgICAgICAgIH0gZWxzZSBpZiAocmVsWSA+IHJlbFgpIHsKICAgICAgICAgICAgICAgIC8vIFRyaWFuZ2xlIGRyb2l0CiAgICAgICAgICAgICAgICByZWxYID0gcmVsWCAtIHNpemUvMjsKICAgICAgICAgICAgICAgIHJlbFkgPSByZWxZIC0gc2l6ZTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBzaXplIC89IDI7CiAgICB9CiAgICAKICAgIHJldHVybiB0cnVlOwp9CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShudWxscHRyKTsKICAgIAogICAgaW50IFE7CiAgICBjaW4gPj4gUTsKICAgIAogICAgd2hpbGUgKFEtLSkgewogICAgICAgIGxsIHgsIHk7CiAgICAgICAgY2luID4+IHggPj4geTsKICAgICAgICBjb3V0IDw8IChpc1JlZCh4LCB5KSA/IDEgOiAwKSA8PCAiXG4iOwogICAgfQogICAgCiAgICByZXR1cm4gMDsKfQ==