#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";
        }
    }
}
