import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

for i in range(I()):
    n,m=li()
    ans=((n)*(n+1))//2
    p=(n-m)//(m+1)
    ans-=((p*(p+1))//2)*(m+1)
    ans-=(p+1)*((n-m)%(m+1))
    print(ans)