#include <bits/stdc++.h>
using namespace std;
const int N = 100014;
long long t;
long long n, m;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long res = n - m;
    long long ans =
        (n + 1) * n / 2 -
        ((((res / (m + 1)) + 1) * (res / (m + 1)) / 2) *
         (m + 1 - (res % (m + 1)))) -
        ((((res / (m + 1)) + 2) * ((res / (m + 1)) + 1) / 2) * (res % (m + 1)));
    cout << ans << endl;
  }
  return 0;
}
