import sys
def fun(x):
    return (x*(x+1))//2
for _ in range(int(input())):
    n,m=map(int,sys.stdin.readline().split())
    emp=n-m
    if(emp>=(m+1)):
        xx=emp//(m+1)
        if(emp%(m+1)==0):
            times=(m+1)
            print(fun(n)-fun(xx)*times)
        else:
            times=m+1
            rem=(emp%(m+1))
            print(fun(n)-fun(xx+1)*rem-fun(xx)*(times-rem))
    else:
        print(fun(n)-emp)