#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = m + 2 * m * (n - 2 * m);
    if (n - 2 * m < 0) {
      ans = n * (n + 1) / 2 - (n - m);
      cout << ans << endl;
      continue;
    }
    long long l = n - 2 * m + 1;
    ans += (n + 1) * (n - l);
    ans -= (n * (n + 1) / 2 - l * (l + 1) / 2);
    cout << ans << endl;
  }
}
