#include <bits/stdc++.h>
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long n, m, s, sum = 0;
    scanf("%lld%lld", &n, &m);
    s = n - m;
    sum = s * m + m;
    if (m > 0) sum += m * (m - 1) / 2;
    if (s > 0) sum += s * (s - 1) / 2;
    printf("%lld\n", sum);
  }
}
