

import java.io.*;

import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int t = in.nextInt();
        while (t-- > 0) {
            int n = in.nextInt();
            int m = in.nextInt();
            long ans = (long) (n + 1) * n / 2;
            long k = (n - m) / (m + 1);
            long ost = (n - m) % (m + 1);
            long HIV = (m + 1 - ost) * (k * (k + 1) / 2);
            HIV += (ost) * ((k + 2) * (k + 1) / 2);
            in.out.println(ans - HIV);
        }
        in.out.close();
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    PrintWriter out;

    FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    FastScanner(String in, String out_) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(in));
        out = new PrintWriter(out_);
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}