/* 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
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc=new FastReader();
		int t=sc.nextInt();
		while(t-->0){
		    long n=sc.nextLong();
		    Long m=sc.nextLong();
		    if(m==0) {
	    	System.out.println(0);
    	    }else {
    		    long n0=n-m;
    		    long spacefor0=m+1;
    		    long numofeq0=n0/spacefor0;
    		    long numofnteq0=n0%spacefor0;
    		    long spaceforeq0=spacefor0-numofnteq0;
    		    long val=(spaceforeq0*numofeq0*(numofeq0+1))/2;
    		    long val1=(numofnteq0*(numofeq0+1)*(numofeq0+2))/2;
    		    long tot=(n*(n+1))/2;
    		    System.out.println(tot-val-val1);
    	    }
	}
    }
}
