#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      long long int ans = (a * (a + 1)) / 2;
      cout << ans << endl;
    } else if (b == 0) {
      cout << 0 << endl;
    } else {
      vector<int> a1;
      for (int i = 1; i <= a; i++) {
        if (i % 2 == 0) {
          a1.push_back(i);
          b--;
        }
        if (b == 0) break;
      }
      int k = 0;
      long long int ans = 0;
      for (int i = 1; i <= a; i++) {
        if (i <= a1[k]) {
          int tem = a - a1[k];
          tem++;
          ans += tem;
        } else {
          while (k < a1.size() && a1[k] < i) k++;
          if (k == a1.size())
            break;
          else {
            int tem = a - a1[k];
            tem++;
            ans += tem;
          }
        }
      }
      ans += b;
      cout << ans << endl;
    }
  }
}
