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