n=int(input())
l1=[]
l2=[]
for x in range(n):
    s=str(input())
    l=s.split(' ',)
    l1.append(int(l[0]))
    l2.append(int(l[1]))
l3=[]
i=0
while(i<n):
    k=l2[i]+1
    z=l1[i]-l2[i]
    q=z//k
    r=z%k
    tz=r*(((q+2)*(q+1))//2)+(k-r)*(((q+1)*(q))//2)
    l3.append((l1[i]*(l1[i]+1))//2-tz)
    i=i+1
for x in l3:
    print(x)