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


    
