#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    int p = n / 2;
    int q = n - m;
    long long int jk = n * (n + 1);
    jk = jk / 2;
    if (q <= p) {
      jk = jk - m;
      cout << jk << endl;
      continue;
    } else {
      long long int a = q / (m + 1);
      long long int b = q % (m + 1);
      long long int x = (a + 1) * (a + 2);
      x = x / 2;
      x = x * b;
      long long int y = (a) * (a + 1);
      y = y / 2;
      y = y * (m + 1 - b);
      x = x + y;
      jk = jk - x;
      cout << jk << endl;
    }
  }
  return 0;
}
