#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool cmpdec(int a, int b) { return a > b; }
long long t, n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long sum = (n * (n + 1)) / 2;
    long long half = floor(n / 2);
    if (m >= half) {
      cout << sum - (n - m) << endl;
    } else {
      long long cnt = m;
      while (cnt--) {
        sum -= 2;
      }
      long long sub = (n - m * 3);
      sum -= ((sub * (sub + 1)) / 2);
      cout << sum << endl;
    }
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
