"""609C"""
# import math
import sys
def main():
	# n ,m= map(int,input().split())
	# a = list(map(int,input().split()))
	n,m = map(int,sys.stdin.readline().split())
	ans = n*(n+1)
	ans = ans//2
	if n==m:
		print(ans)
	elif m==0:
		print(0)
	else:
		temp = n-m
		k = (temp)//(m+1)
		sub  = ((k*(k+1))//2)*(m+1) + (k+1)*(temp%(m+1))
		print(ans-sub)
	return


# main()
def test():
	t = int(input())
	while t:
		main()
		t-=1
test()
