import java.util.*;
import java.io.*;
public class Task{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
static void mat_mul(long[][] a, long[][] b, long[][]tmp,long m){
	int n=a.length;
	for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
              long sum=0;
              for(int k=0;k<n;k++){
                    sum+=b[i][k]*a[k][j];
                    sum%=m;
               }
               tmp[i][j]=sum;
        }
     }
     for(int i=0;i<n;i++){a[i]=tmp[i].clone();}
}
static void fast_mat_exp(long[][] a,long m, long p){
      int n=a.length;
      long[][] res=new long[n][n];
      long[][] res1=new long[n][n];
      long[][] tmp=new long[n][n];
      for(int i=0;i<n;i++){res[i][i]=1;}// identity matrix;
      while(p>0){
            if(p%2==1){
                  mat_mul(res,a,res1,m); // multiply res*a. res1 storing res*a and again assigning it to res.
            }
            p/=2;
                 mat_mul(a,a,tmp,m);
      } 
      //res contains result   
 }
// end
static long[] f;

  static long phi(long n){
  	int k=(int)Math.sqrt(n);
  	long x=1,y=n;
  	for(int i=2;i<=k;i++){
  		boolean b=false;
  		while(n%i==0){
  			n/=i;b=true;
  		}
  		if(b){
  			 y/=i;
  		x*=(long)(i-1);
  		}
  	}
  	if(n>1){x*=(n-1);y/=n;}
  	return x*y;
  }
// 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 p1=(a[0]-a[1])/(a[1]+1),p2=(a[0]-a[1])%(a[1]+1),p3=a[1]+1-p2;
        	long r1=p3*(p1*(p1+1))/2,r2=p2*((p1+1)*(p1+2))/2;
        	res-=r1+r2;
         	out.write(res+"\n");
        	}
        	else{out.write(0+"\n");}
       }
       out.flush();
   }
}

 