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