from bisect import bisect_right as br

a = []
for i in range(1,10**15,2):
    if i*i>10**15:break
    a.append(i*i)

p = [1<<i for i in range(51)]
T = int(input())
# T = 10000
for i in range(T):
    L, R = map(int, input().split())
    # L, R = 1, 10**15
    res = 0
    for j in range(51):
        n = br(a,R//p[j])-br(a,(L-1)//p[j])
        res += n
        res %= 2
    print(res)