#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  scanf("%lld %lld", &n, &m);
  long long ans = n * (n + 1) / 2;
  long long p = (n - m) / (m + 1), q = (n - m) % (m + 1);
  ans -= p * (p + 1) / 2 * (m + 1 - q);
  ans -= (p + 1) * (p + 2) / 2 * q;
  printf("%lld\n", ans);
  return;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
