T=int(input()) for i in range(T): N,M=map(int,input().split()) if N>M: print(M//2) else: print((M-N+2)*(M-N+3)//2-3+M//2)