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

public class C{
    static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException{
        int t = Integer.parseInt(sc.readLine());
        while(t-->0){
            solve();
        }
        bw.flush();
        bw.close();
    }

    public static void solve() throws IOException{
        String sx[] = sc.readLine().split(" ");
        long n = Integer.parseInt(sx[0]);
        long m = Integer.parseInt(sx[1]);
        long k=(n-m)/(m+1);
		long l=(n-m)%(m+1);
		long s = n*(n+1)/2;
		 s-=(k*(k+1)/2)*(m+1); 
		 s-=(k+1)*l;
        bw.write(String.valueOf(s) + "\n");
        
        
    }
}