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

// Created by @thesupremeone on 11/05/21
public class AyoubFunction {

    long subs(long n){
        return ((n*(n+1))/2);
    }

    void solve() throws IOException {
        int ts = getInt();
        for (int t = 1; t <= ts; t++){
            long n = getInt();
            long m = getInt();
            long p = n-m;
            if(p<=m+1){
                println(subs(n)-p);
            }else{
                long s = p/(m+1);
                long u = p%(m+1);
                long v = m+1-u;
                println(subs(n)-(u*subs(s+1))-(v*subs(s)));
            }
        }
    }

    public static void main(String[] args) throws Exception {
        if (isOnlineJudge()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            new AyoubFunction().solve();
            out.flush();
        } else {
            localJudge = new Thread();
            in = new BufferedReader(new FileReader("input.txt"));
            out = new BufferedWriter(new FileWriter("output.txt"));
            localJudge.start();
            new AyoubFunction().solve();
            out.flush();
            localJudge.suspend();
        }
    }
    static boolean isOnlineJudge(){
        try {
            return System.getProperty("ONLINE_JUDGE")!=null
                    || System.getProperty("LOCAL")==null;
        }catch (Exception e){
            return true;
        }
    }
    // Fast Input & Output
    static Thread localJudge = null;
    static BufferedReader in;
    static StringTokenizer st;
    static BufferedWriter out;
    static String getLine() throws IOException{
        return in.readLine();
    }
    static String getToken() throws IOException{
        if(st==null || !st.hasMoreTokens())
            st = new StringTokenizer(getLine());
        return st.nextToken();
    }
    static int getInt() throws IOException {
        return Integer.parseInt(getToken());
    }
    static long getLong() throws IOException {
        return Long.parseLong(getToken());
    }
    static void print(Object s) throws IOException{
        out.write(String.valueOf(s));
    }
    static void println(Object s) throws IOException{
        out.write(String.valueOf(s));
        out.newLine();
    }
}