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