#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    if (m * 2 >= n)
      cout << (long long)n * (n + 1) / 2 - n + m << "\n";
    else {
      long long k = n - m, ans = (long long)n * (n + 1) / 2;
      long long l = k / (m + 1), a = k % (m + 1);
      ans -= (l + 2) * (l + 1) / 2 * a;
      ans -= l * (l + 1) / 2 * (m + 1 - a);
      cout << ans << "\n";
    }
  }
}
