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 + 10 ** (-14)) + int(r ** 0.5 / 2 ** 0.5 + 10 ** (-14)) ans2 = int(l ** 0.5 + 10 ** (-14)) + int(l ** 0.5 / 2 ** 0.5 + 10 ** (-14)) print((ans1 + ans2) % 2) for _ in range(int(input())): solve()