#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    unsigned long long n, m;
    unsigned long long z, g, k;
    unsigned long long ans;
    cin >> n >> m;
    z = n - m;
    g = m + 1;
    k = z / g;
    ans = (n * (n + 1) / 2 - k * (k + 1) / 2 * g - (k + 1) * (z % g));
    cout << ans << endl;
  }
  return 0;
}
