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

public class Codeforces {
  public static void main (String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    int t = Integer.parseInt(reader.readLine());
    for (int ii = 0; ii < t; ii++) {

      StringTokenizer tokenizer = new StringTokenizer(reader.readLine(), " ");
      long n = Integer.parseInt(tokenizer.nextToken());
      long m = Integer.parseInt(tokenizer.nextToken());

      long zero = n - m;
      if (zero == n) {
        writer.write(0 + "\n");
      } else if (zero <= n) {
        long totalPoss = (n * (n + 1)) / 2;
        long res = totalPoss - zero;
        writer.write(res + "\n");
      } else{
        long basket = n + 1;
        long evenBasketCounter = basket / zero;
        long residual = zero - (basket * zero);
        long overflowBasket = residual;
        long perfectBasket = basket - residual;
        long overflowBasketCounter = ((evenBasketCounter + 1) * (evenBasketCounter + 2)) / 2;
        long perfectBasketCounter = (evenBasketCounter * (evenBasketCounter + 1)) / 2;
        long totalPoss = (n * (n + 1)) / 2;
        long res = totalPoss - (overflowBasketCounter * overflowBasket) - (perfectBasketCounter * perfectBasket);
        writer.write(res + "\n");
      }
    }
    writer.flush();
  }
}
