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