#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, d;
    cin >> n >> m;
    if (m == 0) {
      cout << 0 << endl;
      continue;
    }
    long long res = (n * (n + 1)) / 2;
    d = m + 1;
    if (m >= floor((double)n / 2.0)) {
      cout << res - (n - m) << endl;
    } else if ((n - m) % d == 0) {
      long long q = (n - m) / d;
      long long k = (q * (q + 1)) / 2;
      k = d * k;
      cout << res - k << endl;
    } else {
      long long q = (n - m) / d;
      long long k = (q * (q + 1)) / 2;
      d--;
      k = d * k;
      q++;
      q = (q * (q + 1)) / 2;
      k += q;
      cout << res - k << endl;
    }
  }
}
