#include <bits/stdc++.h>
using namespace std;
unsigned long long max(unsigned long long a, unsigned long long b) {
  return (a > b) ? a : b;
}
unsigned long long min(unsigned long long a, unsigned long long b) {
  return (a < b) ? a : b;
}
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  while (1) {
    if (a == 0) return b;
    b %= a;
    if (b == 0) return a;
    a %= b;
  }
}
unsigned long long pow(unsigned long long a, unsigned long long b) {
  unsigned long long re = 1, k = a;
  while (b != 0) {
    if (b % 2 == 1) re = (re * k) % 1000000007;
    k = (k * k) % 1000000007;
    b /= 2;
  }
  return re;
}
int main() {
  unsigned long long n, m, i, j, t;
  cin >> t;
  for (unsigned long long ii = 0; ii < t; ii++) {
    cin >> n >> m;
    if (m == 0) {
      cout << "0" << endl;
      continue;
    }
    unsigned long long k = (n - m) / (m + 1);
    unsigned long long g = (n - m) % (m + 1);
    unsigned long long s = 0;
    s += g * ((k + 1) * (k + 2)) / 2;
    s += (m + 1 - g) * (k * (k + 1)) / 2;
    cout << n * (n + 1) / 2 - s << endl;
  }
}
