#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  long long z = n - m, g = m + 1;
  long long k = z / g;
  long long j = k + 1, l = z % g;
  ans = (((n * (n + 1)) / 2) - ((j * (j + 1)) / 2) * l -
         ((k * (k + 1)) / 2) * (g - l));
  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;
}
