cnt = 1 n = 10 ** 15 memo = set() while cnt ** 2 <= n: val = cnt ** 2 cnt2 = 1 while cnt2 * val <= n: memo.add(cnt2 * val) cnt2 *= 2 cnt += 1 memo = list(sorted(memo)) import bisect for _ in range(int(input())): l,r = map(int,input().split()) a = (bisect.bisect(memo,l-1)) b = (bisect.bisect(memo,r)) # print(a,b) if (a - b) & 1: print(1) else: print(0)