import java.io.*;
import java.util.*;
public class b_timing_issue {


	public static void main(String[] args) throws Exception{

		BufferedReader  jk =  new BufferedReader(new InputStreamReader( System.in))  ; 
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)) ; 
		StringTokenizer ana = new StringTokenizer(jk.readLine()) ; 
		int t = Integer.parseInt(ana.nextToken()) ; 
		for(int j=0 ;j<t;j++)
		{
			ana= new StringTokenizer(jk.readLine()) ; 
			long n = Long.parseLong(ana.nextToken()) ; 
			long m = Long.parseLong(ana.nextToken()) ;
			long res =0 ; 
			if(n==m)res = (n)*(n+1)/2 ; 
			else if(m==0) res =0 ; 
			else
			{
				long y = 0 ; 
				if((n-m)%(m+1)==0) {
					long u = (n-m)/(m+1) ; 
					y = u*u*(m+1) ; 
				}
				else
				{
					long  u = (n-m)/(m) ;
					long mod = (n-m)%(m) ; 
					if(u==0)
					{
						y= n-m ;
					}
					else
					{
						y=mod*mod + u*u*m ;
					}
					y= mod*mod   +  m*u*u; 
				}
				res= n*(n+1) -n -y +m ; 
				res =res/2 ; 
			}
			out.println(res);
		} 




		out.flush();
	}

}



