from math import isqrt def sm(x): return isqrt(x)-isqrt(x//2) N=int(input()) for i in range(N): L,R=map(int,input().split()) print((sm(R)-sm(L-1))%2)