import java.util.*;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
 
 
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
	InputReader sc = new InputReader(inputStream);
        int t = sc.nextInt();
 
        while(t-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int zero = n - m;
            int one = m;
 
            int answer = 0;
            if(one >= zero) {
                answer = n * (n+1) / 2;
                answer -= zero;
            } else {
                if(one > 0) {
                    int temp = one + 1;
                    int mok = zero / temp;
                    int remain = zero % temp;
                    int 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;
                }
            }
            System.out.println(answer);
        }
    }

	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());
        }
 
    }
}