def cal(x):
	return (x*(x+1))//2
for _ in range(int(input())):
	n,m=map(int,input().split())
	ans=cal(n)-(n-m)
	if m==0:print(0);continue
	if m<(n//2):
		x=n-(2*m-1)
		if x%2==0:
			ans-=2*cal(x//2-1)
		else:
			ans-=(cal(x//2)+cal(x//2-1))
	print(ans)