#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return (!b) ? a : gcd(b, a % b);
}
long long int calc(long long int n) { return ((n * (n + 1)) / 2); }
void solve() {
  long long int m, n;
  cin >> n >> m;
  long long int n1 = m + 1;
  long long int n0 = n - m;
  long long int tot = calc(n);
  long long int stot = 0;
  long long int div = n0 / n1;
  stot += n1 * calc(div);
  long long int exc = 0;
  exc += (div + 1) * (n0 % n1);
  cout << tot - stot - exc << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
