import sys
import math
from collections import defaultdict,Counter

input=sys.stdin.readline

def print(x):
    sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP3/output.txt",'w')
# sys.stdin=open("CP3/input.txt",'r')
# m=pow(10,9)+7
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    if m==0:
        print(0)
    elif n-m<=m:
        print(n*(n+1)//2-(n-m))
    else:
        d=n-m
        k=d//(m+1)
        d1=d%(m+1)
        print(n*(n+1)//2-(m+1)*(k*(k+1)//2)-(k+1)*d1)