#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect import heapq import functools mod=10**9+7 import sys input=sys.stdin.readline t = int(input()) def count(x): res = 0 if x >= 10 ** 7: sq = int(math.sqrt(x) - 2) while (sq + 1) ** 2 <= x: sq += 1 else: sq = int(math.sqrt(x)) res += sq if x >= 10 ** 7: dsq = int(math.sqrt(x//2) - 2) while (dsq + 1) ** 2 * 2 <= x: dsq += 1 else: dsq = int(math.sqrt(x//2)) res += dsq return res for _ in range(t): l,r=map(int,input().split()) ans = count(r) - count(l-1) print(ans%2)