#include <bits/stdc++.h>
using namespace std;
long long t, n, m, zero, num;
inline long long read() {
  long long s = 0, t = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') c = getchar(), t = -1;
  while (c >= '0' && c <= '9')
    s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
  return s * t;
}
signed main(void) {
  t = read();
  while (t--) {
    n = read();
    m = read();
    zero = n - m;
    num = m + 1;
    long long g = zero / num;
    long long ans =
        (n + 1) * n / 2 - g * (g + 1) / 2 * num - (g + 1) * (zero % num);
    cout << ans << endl;
  }
}
