import sys readline = sys.stdin.readline def f(x): yes = 0 no = 10 ** 9 while no - yes != 1: mid = (yes + no)//2 if mid * mid <= x: yes = mid else: no = mid ans = yes yes = 0 no = 10 ** 9 while no - yes != 1: mid = (yes + no)//2 if 2 * mid * mid <= x: yes = mid else: no = mid return (ans + yes) % 2 T = int(readline()) for _ in range(T): L, R = map(int, readline().split()) print((f(R) - f(L - 1)) % 2)