import sys
input=sys.stdin.readline
t=int(input())
for i in range(t):
    a,b=map(int,input().split())
    d=a-b
    q=d//(b+1)
    r=d%(b+1)
    count=0
    sm=(((q+1)*(q+2))//2)*r
    tot=((q+1)*r)+r
    tot=a-tot
    tot=tot-(b-r)
    if(q>0):
        dv=tot//(q)
        sm=sm+((q*(q+1)*dv))//2
    ans=((a)*(a+1))//2
    print(ans-sm)
