import sys
t = int(sys.stdin.readline())

for _ in range(t):
    n,m = map(int,sys.stdin.readline().split(" "))

    p = (n-m)//(m+1)
    q = (n-m) % (m+1)

    x = q*(p+1)*(p+2)//2
    y = (m+1-q)*p*(p+1)//2

    res = n*(n+1)//2 - (x + y)
    print(res)
