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


def cal():
    n, m = read()
    z = n - m
    g = m + 1
    k = z//g
    n = (n*(n+1))//2
    t = (k*(k+1))//2

    ans = n
    ans -= t*g
    ans -= (k + 1)*(z%g)
    return ans


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