import java.io.*;
import java.util.*;
final public class C {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int tst = Integer.parseInt(br.readLine());
        while(tst-->0) {
            String[] str = br.readLine().split(" ");
            int n = Integer.parseInt(str[0]), m = Integer.parseInt(str[1]);
            long ans = (long)n*(n+1)/2;
            long zeros = (n - m);
            if(m+1>zeros){
                sb.append(ans-zeros).append('\n');
                continue;
            }
            long z = zeros/ (m + 1), k = zeros- (m+1)*(z);
            ans -= (m+1-k)*(z*(z+1)/2);
            ans -= k*((z+1)*(z+2)/2);
            sb.append(ans).append('\n');
        }
        System.out.println(sb);
    }
}