#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt = 1;
  scanf("%d", &tt);
  ;
  while (tt--) {
    long long int i, n, ans = 0, m;
    cin >> n >> m;
    ans = (n + 1) * n;
    ans /= 2;
    if (n - m - m > 1) ans -= (n - m - m - 1);
    if (m == 0)
      cout << 0 << endl;
    else
      cout << ans - (n - m) << endl;
  }
  return 0;
}
