import math def f(x): sq = math.isqrt(x) if 2*sq*sq <= x: return 0 else: return 1 def solve(): l, r = map(int,input().split()) print(f(l-1)^f(r)) t = int(input()) while t > 0: solve() t -= 1