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


def cal():
    n, m = read()
    z = n - m
    k = z//(m+1)
    n = n*(n+1)/2
    t = k*(k+1)/2
    ans = int(n)
    ans -= int(t)*(m+1)
    ans -= (k + 1)*(z%(m+1))
    return ans


for _ in range(int(input())):
    print(cal())