#include <bits/stdc++.h>
using namespace std;
long long solve(vector<long long> &a, long long k) {
  vector<long long> b = a;
  long long temp = -1;
  for (long long i = 0; i < b.size(); i++) {
    if (b[i] == -1) b[i] = k;
  }
  for (long long i = 0; i < b.size() - 1; i++) {
    temp = max(temp, abs(b[i] - b[i + 1]));
  }
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (m == 0) {
      cout << 0 << "\n";
      continue;
    }
    long long k = (n * (n + 1)) / 2;
    if (m <= n) {
      long long x = (n - m) / (m + 1);
      long long y = (n - m) % (m + 1);
      k = k - (x + 1) * (x + 2) * y / 2 - (x + 1) * (m + 1 - y) * x / 2;
    } else {
      k = (k + m - n);
    }
    cout << k << "\n";
  }
  return 0;
}
