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

public class Rextester{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer();
        int t = Integer.parseInt(br.readLine());
        while(t-->0){
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());
            if(k==0){
                sb.append("0\n");
                continue;
            }
            long max = (long)n*(n+1);
            max/=2;
            if(n%2==0){
                if(k>=n/2){
                    sb.append(max-n+k).append("\n");
                }
                else{
                    long left = n-k;
                    long w = left/(k+1);
                    long z = left%(k+1);
                    long more = z*(((w+1)*(w+2))/2)  +   (k+1-z)*(w*(w+1))/2;
                    sb.append(max-more).append("\n");
                }
            }
            else{
                if(k>=(n-1)/2){
                    sb.append(max-n+k).append("\n");
                }
                else{
                    long left = n-k;
                    long w = left/(k+1);
                    long z = left%(k+1);
                    long more = z*(((w+1)*(w+2))/2)  +   (k+1-z)*(w*(w+1))/2;
                    sb.append(max-more).append("\n");
                }
            }
        }
        br.close();
        System.out.println(sb);
    }
}
      