from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n, m = map(int, stdin.readline().split())
	z = n - m
	c = z // (m + 1)
	o = z % (m + 1)
	stdout.write(str(n*(n+1)//2 - o*(c+1)*(c+2)//2 - (m+1-o)*c*(c+1)//2) + '\n')