from math import *
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
    n,ones = map(int,input().split())
    zeros = n-ones
    Low = zeros/(ones+1)
    flrLow = floor(Low)
    ans = n*(n+1)//2
    if flrLow==0:
        print(ans-zeros)
        continue
    if flrLow==Low:
        ans -= (zeros//flrLow)*(flrLow*(flrLow+1)//2)
    elif flrLow!=Low:
        Cnt = zeros%(ones+1)
        ans -= Cnt*((flrLow+1)*(flrLow+2)//2)
        ans -= (ones+1-Cnt)*(flrLow*(flrLow+1)//2)
    print(ans)