#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 10;
vector<long long> v;
long long nxt[MAX], n, m;
void build() {
  nxt[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    if (v.size() > i && v[i] == 1)
      nxt[i] = i;
    else
      nxt[i] = nxt[i + 1];
  }
}
int calc() {
  build();
  int ans = 0;
  for (int i = 0; i < n; i++) ans += (n - nxt[i]);
  return ans;
}
int rec(int cur, int left) {
  if (left == 0)
    return calc();
  else if (cur == n)
    return 0;
  int ret = 0;
  v.push_back(1);
  ret = rec(cur + 1, left - 1);
  v.pop_back();
  v.push_back(0);
  ret = max(ret, rec(cur + 1, left));
  v.pop_back();
  return ret;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    if (m == 0) {
      cout << 0 << endl;
      continue;
    } else if (n < 6) {
      cout << rec(0, m) << endl;
      continue;
    }
    m++;
    n++;
    cout << ((m - 1) * (n * n)) / (2 * m) << endl;
  }
}
