N=int(input()) def lower_square(p,q): #p*n*n <= qを満たす最大のnを出力する x = int((q/p)**0.5 + 5) while p*x*x > q: x-=1 return x for _ in range(N): a,b=map(int,input().split()) ans=0 t=1 while t<=b: ans += ((lower_square(t,b)+1)//2 - (lower_square(t,a-1)+1)//2)%2 ans %=2 t*=2 print(ans)