#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int zeros, parties, div, mod;
    zeros = n - m;
    parties = m + 1;
    div = zeros / parties;
    mod = zeros % parties;
    int res = n * (n + 1) / 2 - (mod * (div + 1) * (div + 2) / 2 +
                                 (parties - mod) * (div + 1) * (div) / 2);
    cout << res << endl;
  }
  return 0;
}
