#include <bits/stdc++.h>
using namespace std;
int calc(int n) { return n * (n - 1) / 2 + n; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    if (k == 0) {
      cout << 0 << endl;
      continue;
    }
    long long int answer = n * (n - 1) / 2 + n;
    n -= k;
    k++;
    answer -= (n % k) * calc(n / k + 1);
    answer -= (k - n % k) * calc(n / k);
    cout << answer << endl;
  }
}
