import sys
input=sys.stdin.readline

def print(x):
    sys.stdout.write(str(x)+"\n")

for _ in range(int(input())):
    n,m=map(int,input().split())
    grps=m+1
    zeach=(n-m)//grps
    extras=(n-m)%grps

    print( (n*(n+1)//2)- (zeach*(zeach+1)//2)*grps -(extras)*(zeach+1) )
    
