#include <bits/stdc++.h>
using namespace std;
struct Dbg {
  template <typename T>
  Dbg& operator,(const T& v) {
    cerr << v << ", ";
    return *this;
  }
} Dbg;
template <typename T>
ostream& operator<<(ostream& _o_, const vector<T>& _v_) {
  if (!_v_.empty()) {
    _o_ << '[';
    copy(_v_.begin(), _v_.end(), ostream_iterator<T>(_o_, ", "));
    _o_ << "\b\b]";
  }
  return _o_;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n, m;
  cin >> n >> m;
  long long ans = (n * (n + 1)) / 2;
  long long cnt = n - min(n, 2 * m);
  if (cnt > 0) {
    ans -= (cnt * m);
    ans -= (cnt * (cnt + 1)) / 2;
  } else {
    ans -= (n - m);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
