#include <bits/stdc++.h>
using namespace std;
int main() {
  int zzz;
  cin >> zzz;
  int n, m, ans, tk;
  for (int zz = 0; zz < zzz; zz++) {
    cin >> n >> m;
    ans = m;
    tk = min(n - 1, 2 * m);
    ans += tk * (tk + 1) / 2;
    ans += ((n - 1) - tk) * 2 * m;
    cout << min((n + 1) * (n) / 2, ans) << endl;
  }
}
