#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long f(long long n) { return n * (n + 1) / 2; }
int main(void) {
  std::ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = n * (n + 1) / 2;
    long long a = n - m, b = m + 1;
    cout << ans - f(a / b + 1) * (a % b) - f(a / b) * (b - a % b) << endl;
  }
  return 0;
}
