import sys
input=sys.stdin.readline
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    zeros=n-m
    if zeros==0:
        print((n*(n+1))//2)
    else:
        div=zeros//(m+1)
        rem=zeros%(m+1)
        print(n*(n+1)//2-rem*(div+1)*(div+2)//2-(m+1-rem)*((div+1)*div)//2)