/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public.
*/
public class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		 Scanner s = new Scanner(System.in);
		 int t=s.nextInt();
		 while(t>0)
		 {
		     int n=s.nextInt();
		     int m=s.nextInt();
		     long ans=n*(n+1);ans/=2;
		     int chunk=m+1;
		     int zeros=n-m;
		     if(zeros%chunk==0)
		     {
		        long left=zeros/chunk;
		        long mul=left*(left+1);mul/=2;mul*=chunk;ans-=mul;
		     }
		     else
		     {   long modd=zeros%chunk;
		         long left=zeros/chunk;left++;
		         
		         long mul=left*(left+1);mul/=2;mul*=modd;ans-=mul;
		         mul=0;modd=chunk-modd; left--;
		         long overs=chunk-modd;
		         mul=left*(left+1);mul/=2;mul*=overs;ans-=mul;
		     }
		     System.out.println(ans);
		    
		      
		     
		     
		     t--;
		 }
	}
}
