from sys import stdin,stdout,setrecursionlimit
def fn(n):
    return (n*(n+1))//2
for _ in range(int(stdin.readline())):
    # n=int(stdin.readline())
    # n,k=list(map(int,stdin.readline().split()))
    n,k=list(map(int,stdin.readline().split()))
    zeros=n-k
    partitions=k+1
    zeros_per_partition=zeros//partitions
    rem=zeros%partitions
    xx=rem*fn(zeros_per_partition+1)
    normal=(partitions-rem)*fn(zeros_per_partition)
    print(fn(n)-(xx+normal))