for case 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:
		c = m + 1
		z = n - m
		f_l = z//c
		x = z % c
		v = c - x
		t -= (((f_l + 1)*(f_l + 2)//2)*x + (f_l*(f_l + 1)//2)*v)
		print t


