import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18 LI = lambda : list(map(int, input().split())) def debug(_l_): for s in _l_.split(): print(f"{s}={eval(s)}", end=" ") print() def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] sys.setrecursionlimit(3*10**5+10) t = int(input()) for _ in range(t): l,r = list(map(int, input().split())) to = l+r num = to-2*l if num<=109: ans = 0 for v in range(2*l, to+1, 1): if (v-2*l)%4<=1: ans ^= v else: k = ((l+r-1) - (2*l)) // 4 ans = (k+1)%2 for v in range(2*l+k*4+2, to+1): if (v-2*l)%4<=1: ans ^= v print(ans)