#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    if (m == 0) {
      cout << "0" << endl;
      continue;
    }
    long long int x = n - m;
    long long int part = m + 1;
    long long int rem = x % part;
    part = x / part;
    long long int y = part * (part + 1);
    y /= 2;
    y *= (m + 1);
    rem += y;
    long long int ans = n * (n + 1);
    ans /= 2;
    ans -= rem;
    ans = max(ans, 0ll);
    cout << ans << endl;
  }
  return 0;
}
