#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long long n, m;
  long long x, y, ans, tmp, tmp2;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &n, &m);
    ans = n * (n + 1) / 2;
    y = min(m + 1, n - m);
    x = n - m;
    if (y == 0) {
      printf("%lld\n", ans);
      continue;
    }
    tmp = x / y;
    tmp2 = x % y;
    ans -= tmp * (tmp + 1) / 2 * y;
    ans -= tmp2 * (tmp + 1);
    printf("%lld\n", ans);
  }
  return 0;
}
