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 z = n - m;
      long g = m + 1;

      long smallBasketSize = z / g;
      long bigBasketSize = smallBasketSize + 1;

      long smallBasketCost = (smallBasketSize * (smallBasketSize + 1)) / 2;
      long bigBasketCost = smallBasketSize + 1;

      long bigBasketNumber = bigBasketCost * (z % g);
      long smallBasketNumber = smallBasketCost * g;

      long totalPoss = (n * (n + 1)) / 2;
      long res = totalPoss - smallBasketNumber - bigBasketNumber;
      writer.write(res + "\n");
    }
    writer.flush();
  }
}
