#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n, n2, m, soma, m2, aux, start, m3;
  cin >> t;
  while (t--) {
    soma = 0;
    cin >> n >> m;
    n2 = n;
    m2 = min(m, n / 2);
    aux = 0;
    m2 *= 2;
    start = (n2 - m2);
    while (m2) {
      soma += m2;
      n--;
      if (n <= n2 - start) m2--;
    }
    soma += m;
    cout << soma << "\n";
  }
}
