#include #include using namespace std; using namespace atcoder; using ll = long long; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < n; i++) ll check(ll x){ if(x == 0) return 0; ll ok = 0; ll ng = 1000000000 + 1; while(abs(ok - ng) > 1){ ll mid = (ok + ng) / 2; if(mid * mid <= x) ok = mid; else ng = mid; } ll ret = ok; ok = 0; ng = 1000000000 + 1; while(abs(ok - ng) > 1){ ll mid = (ok + ng) / 2; if(2 * mid * mid <= x) ok = mid; else ng = mid; } ret += ok; return ret; } int main(void) { ll t; cin >> t; while(t--){ ll l, r; cin >> l >> r; ll ans = check(r) - check(l - 1); cout << ans % 2 << endl; } return 0; }