#include <bits/stdc++.h>
using namespace std;
long long n, m, q, z, i, j, k, l, r, t, a, b, c;
int main() {
  cin >> q;
  while (q--) {
    cin >> n >> m;
    k = (n + 1) * n / 2;
    a = (n - m) / (m + 1);
    if ((n - m) % (m + 1) == 0) {
      cout << k - a * (a + 1) / 2 * (m + 1) << endl;
    } else {
      t = (n - m) % (m + 1);
      if (a > 0)
        cout << k - a * (a + 1) / 2 * m - (a + t) * (a + t + 1) / 2 << endl;
      else
        cout << k - t;
    }
  }
  return 0;
}
