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: if (R-L)%8<=4: print(1) else: print(0) elif (R-L)%8==0: print(R+L) else: print((R+L)^1)