def calc(x): count = 0 l = 0 r = 10**10 while r > l + 1: m = (r+l)//2 if m**2 <= x: l = m else: r = m count += l l = 0 r = 10**10 while r > l + 1: m = (r+l)//2 if m**2*2 <= x: l = m else: r = m count += l return count def solve(): l,r = map(int,input().split()) ans = calc(r)-calc(l-1) return ans%2 t = int(input()) for _ in range(t): print(solve())