#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  int t;
  cin >> t;
  long long int m, n;
  while (t--) {
    cin >> n >> m;
    long long int z = n - m;
    long long int g = m + 1;
    long long int k = z / g;
    cout << n * (n + 1) / 2 - k * (k + 1) * g / 2 - (k + 1) * (z % g) << endl;
  }
  return 0;
}
