#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long o = (n - m);
  long long base = o / (m + 1);
  long long rem = o % (m + 1);
  long long mintot =
      base * (base + 1) / 2 * (m + 1 - rem) + (base + 1) * (base + 2) / 2 * rem;
  cout << (n) * (n + 1) / 2 - mintot << "\n";
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
