#code
import sys
import math as mt
input=sys.stdin.buffer.readline
t=int(input())

for __ in range(t):
    #n=int(input())      
    n,m=(map(int,input().split()))  
    #l=list(map(int,input().split()))
    k=(n-m)//(m+1)
    ans=n*(n+1)//2-(k*(k+1)//2)*(m+1)
    ans-=(n-m)%(m+1)*(k+1)
    print(ans)    
				   		  					   	  		 		  		