#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, m;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &n, &m);
    long long k = (n - m) / (m + 1);
    long long l = (n - m) % (m + 1);
    long long sum = n * (n + 1) / 2;
    sum -= (k * (k + 1) / 2) * (m + 1);
    sum -= (k + 1) * l;
    cout << sum << endl;
  }
  return 0;
}
