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