import sys
input=sys.stdin.readline
a=int(input())
for i in range(a):
    x,y=map(int,input().split())
    one=y
    zero=x-y
    if(one>=zero):
        print(((x*(x+1))//2)-zero)
    else:
        if(one==0):
            print(0)
            continue;
        else:
            t=zero//one
            r=zero%one
            ka=r*((t+1)*(t+2)//2)+(one-r)*((t*(t+1))//2)
            print((x*(x+1))//2-ka+1)

    




    
