#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << '\n';
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << '\n';
}
vector<vector<long long> > v(200005);
vector<long long> dad;
vector<long long> intime;
vector<long long> outtime;
vector<long long> depth;
vector<bool> vis;
long long timer = 0;
void treemoves(long long n) {
  dad.assign(n + 1, 1);
  intime.assign(n + 1, 0);
  outtime.assign(n + 1, 0);
  depth.assign(n + 1, 0);
  vis.assign(n + 1, false);
}
void dfs_calc(long long root) {
  vis[root] = true;
  intime[root] = timer++;
  for (auto i : v[root]) {
    if (!vis[i]) {
      depth[i] = depth[root] + 1;
      dad[i] = root;
      dfs_calc(i);
    }
  }
  outtime[root] = timer++;
}
void oblivious() {
  long long n, m;
  cin >> n >> m;
  long long z = n / 2;
  long long ans;
  if (z > m) {
    ans = 2 * (m * n - m * m);
  } else {
    ans = 2 * (z * n - z * z);
    m -= z;
    ans += m;
  }
  cout << ans << '\n';
}
signed main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    oblivious();
  }
  return 0;
}
