#include <bits/stdc++.h>
using namespace std;
namespace red {
long long h;
long long n, m;
long long ret;
inline void main() {
  cin >> h;
  while (h--) {
    cin >> n >> m;
    ret = 0;
    if (!m) {
      puts("0");
      continue;
    }
    if (m >= (n >> 1)) {
      ret = ((n) * (n - 1)) >> 1;
      ret += m;
      printf("%lld\n", ret);
    } else {
      long long l = 1, r = n;
      long long t = 1;
      while (l <= r) {
        if (m * ((l + r) >> 1) <= n - ((l + r) >> 1) + 1)
          t = ((l + r) >> 1), l = ((l + r) >> 1) + 1;
        else
          r = ((l + r) >> 1) - 1;
      }
      ret = ((1 + t) * t) >> 1;
      ret *= m;
      n = n - t;
      ret += ((1 + n) * n) >> 1;
      printf("%lld\n", ret);
    }
  }
}
}  // namespace red
signed main() {
  red::main();
  return 0;
}
