import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)throws Exception
	{
	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter pw=new PrintWriter(System.out);
	    int t=Integer.parseInt(br.readLine());
	    while(t-->0)
	    {
	        String s[]=(br.readLine()).split(" ");
	        long n=Long.parseLong(s[0]);
	        long m=Long.parseLong(s[1]);
	        long tot=0l;
	        tot+=n*(n+1l)/2l;
	        long quo=(n-m)/(m+1);
	        long rem=(n-m)%(m+1);
	        long minus1=(((quo+1l)*(quo+2l))/2l)*rem;
	        long minus2=((quo*(quo+1))/2l)*(m+1-rem);
	        tot-=minus2;
	        tot-=minus1;
	        pw.println(tot);
	    }
	    pw.flush();
	}
}
