#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long gcd, masks, mask, i, h, d, l, r, j, k, n, ans, x, y, z, x1, y1, p,
      x2, y2, m, root, t, sum, size, ind;
  cin >> t;
  while (t--) {
    long long tot, zer, one;
    cin >> tot >> one;
    zer = tot - one;
    k = zer / (one + 1);
    p = k + 1;
    x = zer % (one + 1);
    y = (one + 1 - x);
    cout << (tot * tot + tot) / 2 - x * (p * p + p) / 2 - y * (k * k + k) / 2
         << "\n";
  }
  return 0;
}
