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