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