#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int total = (n * (n + 1)) / 2;
    if ((n - m) - m <= 1)
      cout << total - (n - m) << "\n";
    else
      cout << total - m - ((n - 2 * m) * (n - 2 * m + 1)) / 2 << "\n";
  }
  return 0;
}
