#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  int z = n - m, g = m + 1;
  int k = z / g;
  ans = (((n * (n + 1)) / 2) - ((k * (k + 1)) / 2) * g - ((k + 1) * (z % g)));
  cout << ans << endl;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
