import sys,math input=lambda:sys.stdin.readline().rstrip() def solve(): L,R=map(float,input().split()) ans=0 while R>0.5: right=math.floor((pow(R,0.5)+1)/2) left=math.ceil((pow(L,0.5)+1)/2) ans^=(right-left+1)%2 R/=2 L/=2 print(ans) T=int(input()) for i in range(T): solve()