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