for _ in range(input()):
	n,m=map(int,raw_input().split())
	t=n*(n+1)/2
	p=n//2
	if m>=p:
		print t-(n-m)
	else:
		a=n-m
		b=m+1
		r=a%b
		x=a//b
		s=b-r
		t-=(r*(x+1)*(x+2)//2+s*(x+1)*x//2)
		print t