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