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

public class Main {

    private static long find_s(long a, long b) {
        return (a + 1) * a / 2 * b;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter printWriter = new PrintWriter(System.out);

        try {

            int t =  scanner.nextInt();

            for (int i = 0; i < t; i++) {

                long n = scanner.nextLong();
                long m = scanner.nextLong();
                long zc = n - m;
                long dd = zc / (m + 1);
                long kk = find_s(dd + 1, zc % (m + 1)) + find_s(dd , (m + 1) - zc % (m + 1));

                printWriter.println(find_s(n, 1) - kk);
            }

        } finally {
            scanner.close();
            printWriter.close();
        }

    }

}

