#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long ans = (long long)n * ((long long)n + 1) / 2LL;
    int z = n - m;
    int k = z / (m + 1);
    ans -= (long long)(m + 1) * (long long)k * (long long)(k + 1) / 2LL;
    ans -= (long long)(z % (m + 1)) * (long long)(k + 1);
    cout << ans << '\n';
  }
}
