#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx2")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
  int operator()(int x) const { return x ^ RANDOM; }
};
const int mxN = 2 * 1e5 + 5;
vector<long long> fac(mxN);
long long power(long long x, long long y, long long m) {
  long long res = 1 % m;
  while (y) {
    if (y & 1) {
      res = (res * x) % m;
    }
    y >>= 1;
    x = (x * x) % m;
  }
  return res;
}
void inline solve(int tt) {
  long long n, o;
  cin >> n >> o;
  long long z = n - o;
  long long zsub = 0, dis1 = 0, dis2 = 0, val = 0;
  val = z / (o + 1);
  dis1 = z % (o + 1);
  dis2 = (o + 1) - dis1;
  cout << (n * (n + 1)) / 2 - (dis1 * (val + 1) * (val + 2)) / 2 -
              (dis2 * val * (val + 1)) / 2
       << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 0, t = 1;
  cin >> t;
  while (t--) {
    solve(++tt);
  }
  return 0;
}
