from sys import stdin,stdout

# stdin = open("input.txt", "r");
# stdout = open("output.txt", "w");

t=int(stdin.readline().strip())

for _ in range(t):
	n,m=stdin.readline().strip().split(' ')
	n,m=int(n),int(m)
	tot=(n*(n+1))//2

	n0=n-m
	n1=m
	ans=0
	if n0<=n1:
		ans=tot-n0
	else:
		if n1==0:
			ans=0
		else:
			mn0=n1-1
			remaining_n0=n0-mn0

			ln0=remaining_n0//2
			rn0=remaining_n0-ln0

			ans=tot-((ln0*(ln0+1))//2 + (rn0*(rn0+1))//2 +mn0)

	stdout.write(str(ans)+"\n")