import sys
from fractions import gcd
from math import ceil,sqrt,sin,pi,tan
from collections import defaultdict
read=sys.stdin.buffer.readline
import heapq
mi=lambda:map(int,read().split())
li=lambda:list(mi())
cin=lambda:int(read())

for _ in range(cin()):
    n,m=mi()
    z=n-m
    g=m+1
    k=z//g
    ans=(n*(n+1))//2-(g*k*(k+1))//2-(k+1)*(z%g)

    print(ans)