import sys input = sys.stdin.readline T=int(input()) for tests in range(T): L,R=map(int,input().split()) if (R-L)%4!=0: print((R-L)%2) elif (R-L)%8==0: print(R+L) else: print((R+L)^1)