#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000 + 10;
int n, m;
long long x, y;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    x = n - m;
    y = m + 1;
    long long ans;
    if (x <= y) {
      ans = x;
    } else {
      long long tmp = x / y;
      long long num1 = x % y;
      long long num2 = y - num1;
      ans = num1 * (tmp + 1) * (tmp + 1) + num2 * tmp * tmp;
      ans += x;
      ans /= 2ll;
    }
    long long tot = n * (n + 1) / 2ll;
    printf("%lld\n", tot - ans);
  }
  return 0;
}
