#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int a[n];
    memset(a, 0, sizeof a);
    for (long long int i = 1; i < n && m > 0; i += 2) {
      a[i] = 1;
      m--;
    }
    for (long long int i = 2; i < n && m > 0; i += 2) {
      a[i] = 1;
      m--;
    }
    if (m == 1) a[0] = 1;
    long long int id = 0;
    for (long long int i = 0; i < n; i++)
      if (a[i] == 1) id = i;
    long long int sum = 0;
    for (long long int i = 0; i <= id && id > 0; i++) {
      if (a[i] == 1)
        sum += (n - i);
      else
        sum += (n - i - 1);
    }
    if (n == 1 && m == 1)
      cout << 1 << endl;
    else
      cout << sum << endl;
  }
  return 0;
}
