from sys import stdin
input=stdin.readline
import math
t=int(input())
def g(x):
    return x*(x-1)//2+x
for _ in range(t):
    n,m=map(int,input().split())
    c=n-m
    d=m+1
    c_d=math.ceil(c/d)
    a=c_d*d-c
    b=d-a
    ans=g(n)-g(c_d-1)*a-g(c_d)*b
    print(ans)