#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p, m, k, t, temp, r, s;
  string a, b, c;
  cin >> t;
  for (long long jjj = 1; jjj <= t; jjj++) {
    cin >> n >> m;
    k = n * (n + 1) / 2;
    r = n - m;
    p = r / (m + 1);
    s = r % (m + 1);
    cout << k - (p * (p + 1) / 2 * (m + 1) + (p + 1) * s) << "\n";
  }
}
