from bisect import bisect_left, bisect_right import sys int1 = lambda x: int(x) - 1 # input = lambda: sys.stdin.buffer.readline() input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) i1 = lambda: int1(input()) mi = lambda: map(int, input().split()) mi1 = lambda: map(int1, input().split()) li = lambda: list(mi()) li1 = lambda: list(mi1()) lli = lambda n: [li() for _ in range(n)] INF = float("inf") mod = int(1e9 + 7) # mod = 998244353 def solve(x): ok = 0 ng = lim while ng - ok > 1: m = ok + ng >> 1 if m ** 2 <= x: ok = m else: ng = m return ok lim = 31622777 for _ in range(ii()): l, r = mi() ans = solve(r) + solve(r // 2) ans -= solve(l - 1) + solve((l - 1) // 2) print(ans & 1)