import java.util.Scanner;

public class CF {
	public static Scanner cin = new Scanner(System.in);
	long n, m;
	long s(long k) {
		return (k + 1) * k / 2;
	}
	StringBuffer sb = new StringBuffer();
	public void solve() {
		n = cin.nextLong();
		m = cin.nextLong();
		long a = n - m;
		long b = m + 1;
		long x = a / b;
		long y = a % b;
		long ans = s(n) - s(x)*(b-y) - s(x+1)*y;
		sb.append(ans).append("\n");
	}
	public static void main(String[] args) {
		CF cf = new CF();
		int k = cin.nextInt();
		while (k -- > 0) {
			cf.solve();
		}
		System.out.println(cf.sb.toString());
	}
}
