#include <bits/stdc++.h>
bool QQQQ;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, -1, 1, 1, -1, 1, -1};
using namespace std;
long long ttt = 1;
long long n, m, z;
void solve() {
  cin >> n >> m;
  z = (n - m) / (m + 1);
  cout << (n * (n + 1) / 2) -
              ((z * (z + 1) / 2 * ((m + 1) - ((n - m) % (m + 1)))) +
               ((z + 1) * (z + 2) / 2 * ((n - m) % (m + 1))))
       << endl;
}
int main() {
  QQQQ = 0;
  scanf("%I64d", &ttt);
  for (int i = 1; i <= ttt; i++) solve();
  if (QQQQ) printf("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  ;
}
