import sys
input=sys.stdin.readline
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    fs=(n*(n+1))/2
    zero=n-m
    k=zero//(m+1)
    totalk=(k*(k+1))/2
    output=fs-totalk*(m+1)-(k+1)*(zero%(m+1))
    print(int(output))
    
                
    


    
