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