#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    if (m == 0) {
      cout << "0" << endl;
      continue;
    }
    if (n == 1) {
      cout << "1" << endl;
      continue;
    }
    long long ans = n * (n - 1) / 2;
    ans += m;
    long long c0 = n - m;
    long long op = m + 1;
    if (c0 % op == 0) {
      long long kk = c0 / op;
      ans -= op * kk * (kk - 1) / 2;
      cout << ans << endl;
    } else {
      long long kk = c0 / op;
      long long mod = c0 % op;
      long long aa = mod * (kk + 1) * (kk) / 2;
      long long bb = (op - mod) * kk * (kk - 1) / 2;
      ans -= (aa + bb);
      cout << ans << endl;
    }
  }
  return 0;
}
