#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  bool f = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x = f ? -x : x;
}
int t;
int main() {
  read(t);
  while (t--) {
    long long n, m1;
    read(n);
    read(m1);
    long long m0 = n - m1;
    long long ans = n * (n + 1) / 2;
    if (m1 == 0) {
      cout << 0 << endl;
      continue;
    }
    if (m0 <= m1) {
      ans -= m0;
      cout << ans << endl;
    } else {
      long long t1 = m0 / (m1 + 1);
      long long t2 = m0 % (m1 + 1);
      ans -= t2 * (t1 + 2) * (t1 + 1) / 2;
      ans -= (m1 + 1 - t2) * (t1 + 1) * t1 / 2;
      cout << ans << endl;
    }
  }
  return 0;
}
