#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, o;
    cin >> n >> o;
    int m = n - o;
    int k = o + 1;
    long long total = 1LL * n * (n + 1) / 2;
    int kom = m / k, beshi = m / k + 1;
    int beshicount = m % k, komcount = k - m % k;
    total -= 1LL * komcount * kom * (kom + 1) / 2;
    total -= 1LL * beshicount * beshi * (beshi + 1) / 2;
    cout << total << endl;
  }
}
