import java.util.*;
import java.io.*;
public class Task{
// taking inputs
static BufferedReader s;
static String read() throws IOException{String line="";while(line.length()==0){line=s.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
// ends
public static void main(String[] args) throws  IOException{
       s=new BufferedReader(new InputStreamReader(System.in));
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       	StringBuilder sb=new StringBuilder();
        long t=int_v(read());
        while(t--!=0){
        	long[] a=long_arr();
        	if(a[1]!=0){
        		long res=(a[0]*(a[0]+1))/2;;
        	long k=(a[0]-a[1])/(a[1]+1);
        	long res1=(k*(k+1))/2,res2=0;
        	res1*=a[1];
        	res2=a[0]-a[1]-a[1]*k;
        	res2=(res2*(res2+1))/2;
        	res-=res1+res2;
         	out.write(res+"\n");
        	}
        	else{out.write(0+"\n");}
       }
       out.flush();
   }
}

 