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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int t = in.nextInt();

        while(t-- > 0) {
            long n = in.nextInt();
            long m = in.nextInt();
            long zero = n - m;
            long one = m;

            long answer = 0;
            if(one >= zero) {
                answer = n * (n+1) / 2;
                answer -= zero;
            } else {
                if(one > 0) {
                    long temp = one + 1;
                    long mok = zero / temp;
                    long remain = zero % temp;
                    long cnt = temp;

                    if(remain > 0) {
                        answer -= mok * (mok+1) / 2 * remain;
                        cnt -= remain;
                    }

                    answer += n * (n+1) / 2;
                    answer -= zero;
                    answer -= mok * (mok-1) / 2 * cnt;
                }
            }
            out.println(answer);
        }
        
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
