import java.io.*;
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;

public class D3 {

	static long nc2(long n) {
		if(n==1)
			return 1;
		return n*(n+1)/2;
	}
	public static void main(String[] args) throws IOException{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
//		int t=1;
		int t=parseInt(in.readLine());
		
		while(t-->0) {
			String ss[]=in.readLine().split(" ");
			long n=Long.parseLong(ss[0]);
			long m=Long.parseLong(ss[1]);
			long nz=n-m;
			if(nz==0) {
				System.out.println(nc2(m));
				continue;
			}
			long z=(n+1)/2;
			long part=-1;
			if(m<z) {
				part=m+1;
			}
			else {
				part=n-m;
			}
//			System.out.println("z="+z+" m="+m+" part="+part+" nz="+nz);
			long ans=0;
			if(nz%part==0) {
				long div=nz/part;
				ans+=part*nc2(div);
			}
			else {
				long div=nz/part;
				ans+=part*nc2(div);
				ans+=nc2(div+1);
			}
			System.out.println(nc2(n)-ans);
		}
	}
}
