T = int(input()) def calc(l,r): if r - l <= 10: ans = 0 for i in range(l,r + 1): for j in range(i,r + 1): if i + j > l + r:continue ans ^= (i + j) return ans u = (r - l) // 4 if (u - 1) % 2 == 0: ans = 1 else: ans = 0 for j in range(2 * l + 4 * u,l + r + 1): ans ^= j for j in range(2 * l + 4 * u + 2,l + r + 1): ans ^= j return ans for _ in range(T): l,r = map(int,input().split()) print(calc(l,r))