#include <bits/stdc++.h>
using namespace std;
long long int count(long long int n) {
  long long int w = (n * (n + 1));
  w /= 2;
  return w;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, i, j;
    cin >> n >> m;
    long long int x = n / 2;
    if (m >= x) {
      long long int w = n - m;
      cout << count(n) - w << "\n";
    } else {
      long long int w = n - 2 * m;
      cout << count(n) - count(w) - m << "\n";
    }
  }
}
