import java.util.Scanner;
import java.lang.Math;
public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner (System.in);
		int T = s.nextInt();
		int[] result;
		result = new int [T];
		for (int i=0;i<T;i++)
		{
			int n = s.nextInt();
			int m = s.nextInt();
			int k = (n-m)/(m+1);
			int b = n-m-(m+1)*k;
			int a = m+1-b;
			result[i] = (n+1)*n/2-a*(k+1)*k/2-b*(k+2)*(k+1)/2;
			
		}
		for (int i=0;i<T;i++)
		{
			System.out.println(result[i]);
		}
		s.close();
	}

}
