#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int iiii = 0; iiii < t; iiii++) {
    long long n, m;
    cin >> n >> m;
    long long ans = n * (n + 1) / 2;
    long long zero = n - m, part = m + 1;
    long long mini = zero / part, more = mini + 1;
    mini = mini * (mini + 1) / 2;
    more = more * (more + 1) / 2;
    if (zero % part == 0) {
      cout << ans - mini * part << '\n';
    } else {
      long long cntMore = zero % part, cntMini = part - cntMore;
      cout << ans - (mini * cntMini + more * cntMore) << '\n';
    }
  }
  return 0;
}
