#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (auto u : v) {
    os << u;
    os << ",";
  }
  os << "]"
     << "\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
  os << "{";
  for (auto u : s) {
    os << u;
    if (u != *s.rbegin()) os << ",";
  }
  os << "}"
     << "\n";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "{";
  os << p.first << "," << p.second;
  os << "}"
     << "\n";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
  for (auto p : mp) os << p.first << " : " << p.second << "\n";
  return os;
}
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(3);
}
long long add(long long a, long long b) {
  return (((a % 1000000007) + (b % 1000000007)) % 1000000007 + 1000000007) %
         1000000007;
}
long long multi(long long a, long long b) {
  return (((a % 1000000007) * (b % 1000000007)) % 1000000007 + 1000000007) %
         1000000007;
}
long long modpow(long long a, long long b) {
  if (b <= 0) return 1;
  long long res = modpow(a, b / 2) % 1000000007;
  res = (multi(res, res)) % 1000000007;
  res %= 1000000007;
  return (b % 2 != 0) ? multi(res, a) % 1000000007 : res;
}
long long inv(long long a) {
  return ((modpow(a, 1000000007 - 2)) + 1000000007) % 1000000007;
}
int32_t main() {
  boost();
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long res = 0;
    long long k = min(2 * m, n);
    long long hh = n - m;
    long long tot = (n * (n + 1)) / 2;
    res = tot - ((((n - k) * (n - k - 1)) / 2) + hh);
    cout << res << "\n";
  }
  return 0;
}
