#include <bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main() {
  long long t, i, j, k, l, m, n, ans, x, y, z;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> m >> n;
    x = 0;
    y = 0;
    z = 0;
    if ((2 * n - 1) >= m) {
      ans = ((m) * (m + 1) / 2) - (m - n);
      cout << ans << endl;
      continue;
    }
    if (n == 0) {
      cout << 0 << endl;
      continue;
    }
    x = (n - 1);
    y = m - x - n;
    if (y % 2 == 0) {
      z = y / 2;
      y = z;
    } else {
      z = y / 2;
      y = z + 1;
    }
    ans = ((m) * (m + 1) / 2) - x - ((z) * (z + 1) / 2) - ((y) * (y + 1) / 2);
    cout << ans << endl;
  }
}
