from math import *
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
    n,ones = map(int,input().split())
    zeros = n-ones
    ranGe = [ceil(zeros/(ones+1)),zeros//(ones+1)]
    ans = n*(n+1)//2
    if ranGe[1]==0:
        print(ans-zeros)
        continue
    if ranGe[0]==ranGe[1] and ranGe[0]!=0:
        ans -= (zeros//ranGe[0])*(ranGe[0]*(ranGe[0]+1)//2)
    elif ranGe[1]!=ranGe[0]:
        maxCnt = zeros%ranGe[1]
        ans -= maxCnt*(ranGe[0]*(ranGe[0]+1)//2)
        ans -= (ranGe[1]-maxCnt)*(ranGe[1]*(ranGe[1]+1)//2)
    print(ans)