import sys
 
 
T = input()
 
 
 
 
 
for case in range(T):
 
	n, m = map(int, raw_input().split())
 
	if m >= float(n)/2:
		A = n*(n + 1)/2 - (n - m)
	else:
		# the number of compartments
		c = m + 1
		# splitting the zeros into compartments
		z = n - m
		f_l = z/c
		# calculate how many of f_l and f_u there need 
		n_f_u = z % c
		n_f_l = c - n_f_u
 
		# calculating A
		A = n*(n + 1)/2 - (((f_l + 1)*(f_l + 2)/2)*n_f_u + (f_l*(f_l + 1)/2)*n_f_l)
 
	print A
 
 