import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    private static class Reader implements Closeable {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
        }

        public Reader(String fileName) {
            try {
                reader = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
                throw new IllegalStateException("There is no file with given name");
            }
        }

        public String nextToken() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String nextLine = reader.readLine();
                    if (nextLine == null) {
                        return null;
                    }
                    tokenizer = new StringTokenizer(nextLine);
                } catch (IOException e) {
                    throw new IllegalStateException("I/O Error");
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        @Override
        public void close() throws IOException {
            reader.close();
        }

    }

    public static void main(String[] args) throws IOException {
        Reader reader = new Reader();
        //Reader reader = new Reader("input.txt");
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        int test = reader.nextInt();
        for (int i = 0; i < test; ++i) {
            long n = reader.nextInt();
            long m = reader.nextInt();
            long all = (n + 1) * n / 2;

            long amountOfIncrGr = (n - m) % (m + 1);
            long amountOfDecrGr = m + 1 - (n - m) % (m + 1);

            long decrValue = (n - m) / (m + 1);
            long incrValue = decrValue + ((n - m) % (m + 1) > 0 ? 1 : 0);

            all = all - amountOfDecrGr * (decrValue + 1) * decrValue / 2 - amountOfIncrGr * (incrValue + 1) * incrValue / 2;

            writer.write(Long.toString(all));
            writer.newLine();
        }

        reader.close();
        writer.close();
    }

}
