#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
void solve() {
  long long n, m;
  cin >> n >> m;
  if (2 * m >= n - 1)
    cout << ((n) * (n + 1)) / 2 - (n - m) << endl;
  else {
    cout << 2 * m * (m + 1) << endl;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
