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