#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 6;
long long su[N];
int n;
long long che(long long k) {
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    long long a = (su[i] == -1 ? k : su[i]);
    long long b = (su[i + 1] == -1 ? k : su[i + 1]);
    sum = ((sum) > (abs(a - b)) ? (sum) : (abs(a - b)));
  }
  return sum;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    long long sum = n * (n + 1) / 2;
    n -= m;
    if (n <= (m + 1)) {
      printf("%lld\n", sum - n);
    } else if (m != 0) {
      int k = n % (m + 1);
      n /= m + 1;
      int g = n + 1;
      long long ans = k * g * (g + 1) / 2 + (m + 1 - k) * n * (n + 1) / 2;
      printf("%lld\n", sum - ans);
    } else
      puts("0");
  }
  return 0;
}
