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 s[] = sc.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int ones = Integer.parseInt(s[1]);
        int zeroes = n - ones;
        int groups = ones + 1;

        long total = n * (n+1) / 2;
        
        int eq = zeroes / groups;
        long xl = eq * (eq + 1);
        total = total - (xl * eq * (eq + 1) / 2) - ((eq + 1) * (zeroes %  groups));
        bw.write(String.valueOf(total) + "\n");
        
        
    }
}