#include <bits/stdc++.h>
using namespace std;
long long n, m;
void input() { cin >> n >> m; }
void solve() {
  long long t1 = m;
  long long t0 = n - m;
  if (t1 == 0) {
    cout << 0 << '\n';
    return;
  }
  if (t1 == 1) {
    if (n % 2 == 1) {
      long long x = n / 2 + 1;
      cout << x * (n - x + 1) << '\n';
      return;
    }
    long long x1 = n / 2;
    long long x2 = n / 2 + 1;
    cout << max(x1 * (n - x1 + 1), x2 * (n - x2 + 1)) << '\n';
    return;
  }
  if (t1 > t0) {
    cout << 1LL * n * (n + 1) / 2 - t0 << '\n';
    return;
  }
  long long k = t0 / (t1 + 1);
  long long k1 = t0 % (t1 + 1);
  long long k2 = t1 + 1 - k1;
  long long res1 = (k + 1) * (k + 2) / 2;
  res1 *= k1;
  long long res2 = k * (k + 1) / 2;
  res2 *= k2;
  cout << n * (n + 1) / 2 - res1 - res2 << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    input();
    solve();
  }
  return 0;
}
