from bisect import bisect,bisect_left X = [] for i in range(1,int((10**15)**0.5)+1): X.append(i*i) X.append(2*i*i) X.sort() for _ in range(int(input())): l,r = map(int,input().split()) a = bisect_left(X,l) b = bisect(X,r) print((b-a)%2)