#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 9223372036854775807;
const double efs = 1e-9;
const int mod = 1000000007;
long long min(long long a, long long b) { return a > b ? b : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
int arr[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    if (m == 0) {
      cout << 0 << endl;
    } else {
      long long ans;
      long long cnt_0 = n - m;
      if (m >= cnt_0) {
        ans = (n + 1) * n / 2;
        ans -= cnt_0;
      } else {
        ans = 0;
        long long tmp = n - (m - 1) * 2 - 1;
        ans += ((n - 1) + tmp) * m;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
