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

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        for (int TC=ni();TC>0;TC--) {
            long n=nl(),m=nl();
            long p=n-m;
            long g=p/(m+1);
            long h=p%(m+1);
            long ans=((g*(g+1))/2)*(m+1-h);
            g++;
            ans=ans+((g*(g+1))/2)*(h);
            long a2=(n*(n+1))/2;
            out.println(a2-ans);
        }
        out.flush();
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}