import math
T = int(input())

def func(v):
    ret = 0
    while v>0:
        ret+=math.isqrt(v)-math.isqrt(v//4)
        v=v//2
    return ret

for _ in range(T):
    L,R = map(int, input().split())
    l = func(L-1)
    r = func(R)
    print((r-l)%2)