#include <iostream>
using namespace std;
using ll = long long;
bool isRed(ll x, ll y) {
// Convertir en base 2 pour trouver le motif
while (x > 2) {
// Trouver le plus grand triangle qui contient ce point
ll level = 1;
while ((1LL << level) - 1 < x) level++;
level--;
ll size = (1LL << level) - 1;
// Si le point est dans la moitié inférieure
if (x > size) {
// Calculer la position relative dans la rangée
ll base_start = x - size;
if (y > base_start && y <= base_start + size) {
// Point dans le triangle bleu du milieu
return false;
}
// Ajuster les coordonnées pour le sous-triangle
if (y > base_start + size) {
// Triangle droit
y -= (base_start + size);
}
x -= size;
}
}
// Les points dans le triangle initial sont rouges
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) << '\n';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBsbCA9IGxvbmcgbG9uZzsKCmJvb2wgaXNSZWQobGwgeCwgbGwgeSkgewogICAgLy8gQ29udmVydGlyIGVuIGJhc2UgMiBwb3VyIHRyb3V2ZXIgbGUgbW90aWYKICAgIHdoaWxlICh4ID4gMikgewogICAgICAgIC8vIFRyb3V2ZXIgbGUgcGx1cyBncmFuZCB0cmlhbmdsZSBxdWkgY29udGllbnQgY2UgcG9pbnQKICAgICAgICBsbCBsZXZlbCA9IDE7CiAgICAgICAgd2hpbGUgKCgxTEwgPDwgbGV2ZWwpIC0gMSA8IHgpIGxldmVsKys7CiAgICAgICAgbGV2ZWwtLTsKICAgICAgICAKICAgICAgICBsbCBzaXplID0gKDFMTCA8PCBsZXZlbCkgLSAxOwogICAgICAgIAogICAgICAgIC8vIFNpIGxlIHBvaW50IGVzdCBkYW5zIGxhIG1vaXRpw6kgaW5mw6lyaWV1cmUKICAgICAgICBpZiAoeCA+IHNpemUpIHsKICAgICAgICAgICAgLy8gQ2FsY3VsZXIgbGEgcG9zaXRpb24gcmVsYXRpdmUgZGFucyBsYSByYW5nw6llCiAgICAgICAgICAgIGxsIGJhc2Vfc3RhcnQgPSB4IC0gc2l6ZTsKICAgICAgICAgICAgaWYgKHkgPiBiYXNlX3N0YXJ0ICYmIHkgPD0gYmFzZV9zdGFydCArIHNpemUpIHsKICAgICAgICAgICAgICAgIC8vIFBvaW50IGRhbnMgbGUgdHJpYW5nbGUgYmxldSBkdSBtaWxpZXUKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgLy8gQWp1c3RlciBsZXMgY29vcmRvbm7DqWVzIHBvdXIgbGUgc291cy10cmlhbmdsZQogICAgICAgICAgICBpZiAoeSA+IGJhc2Vfc3RhcnQgKyBzaXplKSB7CiAgICAgICAgICAgICAgICAvLyBUcmlhbmdsZSBkcm9pdAogICAgICAgICAgICAgICAgeSAtPSAoYmFzZV9zdGFydCArIHNpemUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHggLT0gc2l6ZTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIC8vIExlcyBwb2ludHMgZGFucyBsZSB0cmlhbmdsZSBpbml0aWFsIHNvbnQgcm91Z2VzCiAgICByZXR1cm4gdHJ1ZTsKfQoKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0cik7CiAgICAKICAgIGludCBROwogICAgY2luID4+IFE7CiAgICAKICAgIHdoaWxlIChRLS0pIHsKICAgICAgICBsbCB4LCB5OwogICAgICAgIGNpbiA+PiB4ID4+IHk7CiAgICAgICAgY291dCA8PCBpc1JlZCh4LCB5KSA8PCAnXG4nOwogICAgfQogICAgCiAgICByZXR1cm4gMDsKfQ==