def f(n): l, r = 0, 10 ** 9 while r - l > 1: m = (l + r) // 2 if m * m <= n: l = m else: r = m return l % 2 t = int(input()) for _ in range(t): l, r = map(int, input().split()) l -= 1 print((f(r) - f(r // 2) - f(l) + f(l // 2)) % 2)