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