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