import java.util.*;

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
  
public class code
{ 
    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) 
    { 
        FastReader in=new FastReader(); 
        int  t = in.nextInt();
  		while (--t>=0) 
  			{
  				int i,j;
  				int cnt=0;
  				long n = in.nextLong();
  				long m = in.nextLong();
  				//int a[] = new int[n];
  				long k = (n-m)/(m+1);
  				if((n-m)%(m+1)==0)
  				{
  					long r = (m+1)*((k*(k+1))/2);
  					long to = ((n)*(n+1))/2;
  					System.out.println(to-r);
  				}
  				else
  				{
  					long l = (n-m)-(m*k);
  					long d = l-k;
  					long c1 = d*(((k+1)*(k+2))/2)+((m+1-d)*(((k)*(k+1))/2));
  					long to = ((n)*(n+1))/2;
  					System.out.println(to-c1);

  				}



  				
  			}
    } 
} 
