t = int(input()) for _ in range(t): n,m = map(int,input().split()) if m <= n: ans = m//2 else: dif = m-n ans = dif*(dif+1)//2 +m//2-2 print(ans)