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