#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long N = 200005;
vector<long long> vis(N);
vector<vector<long long>> adj(N);
void dfs(long long v) {
  vis[v] = 1;
  for (auto i : adj[v]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  return;
}
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long max(long long a, long long b) {
  long long ans = a > b ? a : b;
  return ans;
}
long long min(long long a, long long b) {
  long long ans = a < b ? a : b;
  return ans;
}
long long root(long long a[], long long i) {
  while (a[i] != i) {
    a[i] = a[a[i]];
    i = a[i];
  }
  return i;
}
void unionn(long long a[], long long i, long long j) {
  long long root_i = root(a, i);
  long long root_j = root(a, j);
  a[root_i] = root_j;
  return;
}
vector<long long> v[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (m == 0)
      cout << "0"
           << "\n";
    else if ((2 * m) + 1 >= n || 2 * m == n) {
      long long d = ((n) * (n - 1)) / 2;
      d += m;
      cout << d << "\n";
    } else {
      long long d = m, f = 0;
      long long c = 2 * m;
      c = n - c;
      if (c % 2 != 0) {
        c++;
        f = 1;
      }
      c = (2 * m) + (c / 2) - 1;
      c = ((c + 1) * c) / 2;
      d += (2 * c);
      c = (2 * m) - 1;
      c = ((c + 1) * c) / 2;
      d -= c;
      if (f) {
        long long e = n + 1 - 2 * m;
        e = (2 * m - 1) + e / 2;
        d -= e;
      }
      cout << d << "\n";
    }
  }
  return 0;
}
