#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long ans = (long long)n * (long long)(n + 1) / 2LL;
    int zeroes = n - m;
    int numberOfZeroGroups = m + 1;
    int k = zeroes / numberOfZeroGroups;
    ans -=
        (long long)k * (long long)(k + 1) * (long long)numberOfZeroGroups / 2LL;
    ans -= (long long)(k + 1) * (long long)(zeroes % numberOfZeroGroups);
    cout << ans << "\n";
  }
  return 0;
}
