#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = 1e9;
int a[maxn];
int t;
int main() {
  scanf("%d", &t);
  while (t--) {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    long long t = min(n / 2, m);
    printf("%lld\n", (n - t) * t * 2 + max(0ll, m - t));
  }
  return 0;
}
