#include <bits/stdc++.h>
using namespace std;
long long n, m;
void input() { cin >> n >> m; }
void solve() {
  long long t1 = m;
  long long t0 = n - m;
  if (t1 == 0) {
    cout << 0 << '\n';
    return;
  }
  if (t1 >= t0) {
    cout << 1LL * n * (n + 1) / 2 - t0 << '\n';
    return;
  }
  long long xx = n - 2 * t1;
  long long l = xx / 2;
  long long r = xx / 2 + xx % 2;
  l += 1;
  long long ll = l * (l + 1) / 2;
  long long rr = r * (r + 1) / 2;
  long long z = n * (n + 1) / 2 - ll - rr - t1 + 1;
  cout << z << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    input();
    solve();
  }
  return 0;
}
