#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m, z, g, k;
    cin >> n >> m;
    z = n - m;
    g = m + 1;
    k = z / g;
    cout << ((n * (n + 1)) / 2 - (k + 1) * (z % g) - (((k + 1) * k) / 2) * g)
         << endl;
  }
}
