def solve(l, r): def check(x): if x == 0: return x left = 0 right = 10**9 + 1 while right - left > 1: mid = (left + right) // 2 if mid * mid <= x: left = mid else: right = mid ret = left left = 0 right = 10**9 + 1 while right - left > 1: mid = (left + right) // 2 if 2 * mid * mid <= x: left = mid else: right = mid ret += left return ret num = check(r) - check(l - 1) return num % 2 t = int(input()) for _ in range(t): l, r = map(int, input().split()) print(solve(l, r))