#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    if (n == m) {
      printf("%lld\n", n * (n + 1) >> 1);
      continue;
    }
    if (m == 0) {
      puts("0");
      continue;
    }
    long long z = n - m;
    if (z <= m) {
      printf("%lld\n", (n * (n + 1) >> 1) - z);
      continue;
    }
    long long k = m + 1, each;
    each = z / k;
    long long each1 = z / k + 1;
    long long ss = n * (n + 1) >> 1;
    long long s = each * (each + 1) >> 1, s1 = each1 * (each1 + 1) >> 1;
    printf("%lld\n", ss - ((s1 * (z % k)) + (s * (k - (z % k)))));
  }
  return 0;
}
