#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
map<pair<long long, long long>, long long> mop;
long long solve(long long sz, long long ones) {
  if (sz <= 0 or ones == 0) return 0;
  if (sz == 1) return ones > 0;
  if (ones == sz) return sz * (sz + 1) / 2;
  if (mop.find({sz, ones}) != mop.end()) return mop[{sz, ones}];
  long long mid = (sz + 1) / 2, mid1 = mid + 1, mid3 = mid1 + 1;
  mop[{sz, ones}] =
      max({mid * (sz - mid + 1) + solve(max(mid - 1, sz - mid), ones / 2) +
               solve(min(mid - 1, sz - mid), (ones - 1) / 2),
           mid1 * (sz - mid1 + 1) + solve(max(mid1 - 1, sz - mid1), ones / 2) +
               solve(min(mid1 - 1, sz - mid1), (ones - 1) / 2),
           mid3 * (sz - mid3 + 1) + solve(max(mid3 - 1, sz - mid3), ones / 2) +
               solve(min(mid3 - 1, sz - mid3), (ones - 1) / 2)});
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    printf("%lld\n", solve(n, m));
  }
}
