from sys import stdin, stdout


T = int(stdin.readline())




for case in range(T):
	n, m = map(int, stdin.readline().split())

	g = m + 1
	z = n - m
	k = z//g
	A = n*(n + 1)//2 - (k*(k + 1)//2)*g - (k + 1)*(z % g)


	stdout.write(str(int(A)) + '\n')


