import sys
input=sys.stdin.readline
t=int(input())
for you in range(t):
    l=input().split()
    n=int(l[0])
    m=int(l[1])
    tot=(n*(n+1))//2
    z=(n-m)//(m+1)
    q=(n-m)%(m+1)
    sumi=0
    sumi=q*(((z+1)*(z+2))//2)
    sumi+=(m+1-q)*((z*(z+1))//2)
    print(tot-sumi)
