#include <bits/stdc++.h>
using namespace std;
long long get_tri(long long n) {
  return (((long long)1 + n) * n) / (long long)2;
}
int main() {
  int t;
  scanf("%d", &t);
  for (int tc = 1; tc <= t; tc++) {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long res = get_tri(n);
    long long size = (n - m) / (m + (long long)1);
    long long num_of_size_plus = (n - m) % (m + (long long)1);
    long long num_of_size = (m + (long long)1) - num_of_size_plus;
    res -= num_of_size * get_tri(size);
    res -= num_of_size_plus * get_tri(size + (long long)1);
    printf("%lld\n", res);
  }
  return 0;
}
