from math import isqrt def calc(x,b): a = isqrt(x) if a * a == x: a += b return a for _ in range(int(input())): l,r = map(int,input().split()) ans = calc(r,0) - calc(l,-1) ans += calc(r//2,0) - calc(-(-l//2),-1) print(ans % 2)