#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  while (b) {
    a = a % b, swap(a, b);
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int INF = 1000000000;
long long n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    if (m == 0) {
      cout << "0\n";
      continue;
    }
    long long first = (n + 1) / 2;
    long long ans = first *= first;
    if (n % 2 == 0) {
      ans += first;
    }
    m--;
    if (n % 2 == 1) {
      long long a = (n - 2) / 2;
      if (a >= m) {
        ans += (n * m) - m * (m + 1);
      } else {
        ans += (n * a) - a * (a + 1);
        m -= a;
        ans += m;
      }
    } else {
      long long a = (n - 1) / 2;
      if (a >= m) {
        ans += (n * m) - m * (m + 1);
      } else {
        ans += (n * a) - a * (a + 1);
        m -= a;
        ans += m;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
