import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def solve(L,R): if (L+R)%2: n = (L+R-1)//2-L+1 res = n*(n+1)//2 return res%2 else: n = (L+R-2)//2-L+1 res = n*(n+1)//2 res %= 2 if ((L+R)//2-L+1)%2: return (L+R)^res else: return res for _ in range(int(input())): L,R = mi() print(solve(L,R))