from sys import stdin, stdout
def total(k): return (k*(k+1)) // 2
ans = []
t= int(stdin.readline())
for line in stdin:
    n, m = tuple(map(int,line.split()))
    if m==0:
        ans.append( str(0) )
    else:
        al = total(n)
        zeros = n-m
        #divide into m+1 groups
        k, extra = zeros//(m+1), zeros%(m+1)
        zero_blocks = extra*(k+1) + (m+1)*total(k)
        ans.append(str(al-zero_blocks))
stdout.write('\n'.join(ans))