#include <bits/stdc++.h>
using namespace std;
bool visited[(long long int)1e5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int g = m + 1;
    long long int k = (n - m) / g;
    long long int res = (n - m) % g;
    cout << n * (n + 1) / 2 - k * (k + 1) * (g - res) / 2 -
                (k + 1) * (k + 2) * res / 2
         << endl;
  }
}
