#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long sum = (n + 1) * n / 2;
    n -= m;
    long long sum0 = n / (m + 1);
    long long mod = n % (m + 1);
    if (mod != 0) {
      sum = sum - (1 + sum0 + 1) * (sum0 + 1) / 2 * mod -
            (1 + sum0) * sum0 / 2 * (m + 1 - mod);
      cout << sum << endl;
    } else {
      sum -= (1 + sum0) * sum0 / 2 * (m + 1);
      cout << sum << endl;
    }
  }
  return 0;
}
