#include <bits/stdc++.h>
using namespace std;
int n, m;
void Process() {
  cin >> n >> m;
  long long nZero = (long long)n - (long long)m;
  long long nOne = (long long)m;
  long long gpZero = nOne + 1;
  long long nbZero = nZero / gpZero;
  long long reZero = nZero - gpZero * nbZero;
  cout << n * (n + 1) / 2 - gpZero * nbZero * (nbZero + 1) / 2 -
              reZero * (reZero + 1) / 2
       << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int Tcase;
  cin >> Tcase;
  while (Tcase--) {
    Process();
  }
  return 0;
}
