import sys
input=sys.stdin.readline
t=int(input())
for _ in range(t):
    n,m=list(map(int,input().split()))
    z=n-m
    x=z//(m+1)
    print((n*(n+1))//2 - (m+1-z%(m+1))*((x*(x+1))//2)- z%(m+1)*(((x+1)*(x+2))//2))
