#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, m;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n >> m;
    int s = n - m, kol = m + 1, a = s / kol, ans;
    ans =
        n * (n + 1) / 2 - (kol)*a * (a + 1) / 2 - (s % kol) * (s % kol + 1) / 2;
    if (m > 0) {
      kol = m;
      a = s / kol;
      ans = max(ans, n * (n + 1) / 2 - (kol)*a * (a + 1) / 2 -
                         (s % kol) * (s % kol + 1) / 2);
    }
    if (m > 1) {
      kol = m - 1;
      a = s / kol;
      ans = max(ans, n * (n + 1) / 2 - (kol)*a * (a + 1) / 2 -
                         (s % kol) * (s % kol + 1) / 2);
    }
    cout << ans << endl;
  }
  return 0;
}
