import math T = int(input()) def func(v): return math.isqrt(v)+math.isqrt(v//2) for _ in range(T): L,R = map(int, input().split()) l = func(L-1) r = func(R) print((r-l)%2)