T = int(input()) for i in range(T): L, R = map(int, input().split()) if R == L: print(2*L) elif L%2 == R%2: a = (R-L+2)//2 if a%2 == 0: print((a%4)//2) else: print((R+L)^((a%4)//2)) else: a = (R-L+1)//2 if a%2 == 0: print((a%4)//2) else: print(((a%4)//2)^(L+R)^(L+R-1))