'''input
5
3 1
3 2
3 3
4 0
5 2

'''
import sys
read = lambda: list(map(int,sys.stdin.readline().strip().split()))

# try:
for _ in range(int(input())):
    n,m = read()
    k = n-m
    total = n*(n+1)//2
    total -= min(k,m)
    if k>m:
        d = k-m
        total -= d*(d+1)//2
    print(total)