

/*
TASK: template
LANG: JAVA
 */
import java.io.*;
import java.lang.*;
import java.util.*;

public class C1301 {
    public static void main(String[] args) throws IOException{
        StringBuffer ans = new StringBuffer();
        StringTokenizer st;
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(f.readLine());
        int t = Integer.parseInt(st.nextToken());
        for(; t > 0; t--){
            st = new StringTokenizer(f.readLine());
            long n = Integer.parseInt(st.nextToken());
            long m = Integer.parseInt(st.nextToken());
            long op = (n*(n+1))/2;
            if(n == m) {
                ans.append(op).append("\n");
                continue;
            }else if(m == 0){
                ans.append(0).append("\n"); continue;
            }
            long g = m+1; //number of chunks, 2
            long z = n-m; //number of zeros, 3
            long k = z/g; //number of zeroes in each chunk, 1
            long r = z % g; //number of chunks with an extra zero, 1
            op-= r*(k+1)*(k+2)/2;
            op-=Math.max(0, ((g-r)*k*(k+1)/2));
            ans.append(op).append("\n");
        }
        f.close();


        System.out.println(ans);

    }
}
