def General_Binary_Decrease_Search_Integer(L,R,cond,default=None): """条件式が単調減少であるとき, 整数上で二部探索を行う. L:解の下限 R:解の上限 cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす) default: Rで条件を満たさないときの返り値 """ if not(cond(L)): return default if cond(R): return R L-=1 while R-L>1: C=L+(R-L)//2 if cond(C): L=C else: R=C return L #floor(a^(1/k)) を求める. def Floor_Root(a,k): """floor(a^(1/k)) を求める. a:非負整数 k:正の整数 """ assert 0<=a and 0a: x-=1 return x #================================================== def g(x): y=1 a=0 while y<=x: check=lambda i:y*(2*i-1)**2<=x a+=General_Binary_Decrease_Search_Integer(1,Floor_Root(x//y,2),check,0) y*=2 return a #================================================== T=int(input()) Ans=[0]*T for t in range(T): L,R=map(int,input().split()) Ans[t]=(g(R)-g(L-1))%2 print(*Ans,sep="\n")