#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int32_t main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int res = n * (n + 1) / 2;
    long long int bach = n - m;
    long long int req = bach / (m + 1);
    if (bach <= m) {
      res -= bach;
      bach = 0;
    } else {
      res = res - (req * (req + 1) / 2) * (m + 1);
      long long int rem = bach - (m + 1) * req;
      res = res - (rem * (rem + 1)) / 2;
      res = res - (rem * req);
    }
    cout << res << endl;
  }
}
