import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) def solve(): l, r = mi() l -= 1 ans1 = int(r ** 0.5) + int((2 * r) ** 0.5 / 2) ans2 = int(l ** 0.5) + int((2 * l) ** 0.5 / 2) print((ans1 + ans2) % 2) for _ in range(int(input())): solve()