import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int q=Integer.parseInt(br.readLine());
        for(int x=0;x<q;x++)
        {
            String str[]=br.readLine().split(" ");
            int n=Integer.parseInt(str[0]);
            int m=Integer.parseInt(str[1]);
            int w=n-m;
            if(m>=w||(int)Math.abs(m-w)==1)
            pw.println((long)n*(n+1)/2-w);
            else
            {
                int max=(int)Math.ceil((double)w/(m+1));
                int min=w/(m+1);
                int rem=w%(m+1);
                long ans=(long)n*(n+1)/2-rem*(long)(max)*(max+1)/2-(m+1-rem)*(long)min*(min+1)/2;
                pw.println(ans);
            }
        }
        pw.flush();
        pw.close();
    }
}