import sys
input = sys.stdin.readline
out = sys.stdout
for _ in range(int(input())):
	n,m=map(int,input().split())
	a=(n-m)//(m+1)
	b=(n-m)%(m+1)
	a1=(m+1-b)*(a*(a+1))//2
	b1=b*((a+1)*(a+2))//2
	ans=((n*(n+1))//2)-a1-b1
	out.write(str(ans)+"\n")