T = int(input()) def counts_pow(n,M,k): if M==0: return 0 l,r=0,M while(r-l>1): mid=(r+l)//2 if mid**n*k<=M: l=mid else: r=mid return l for _ in range(T): L, R = map(int,input().split()) count=0 count+=counts_pow(2,R,1)-counts_pow(2,L-1,1) count+=counts_pow(2,R,2)-counts_pow(2,L-1,2) print(count%2)