#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    long long sm = n * (n + 1) / 2;
    if (n <= 2 * m) {
      cout << sm - (n - m) << endl;
    } else {
      long long np = (n + m) / (m + 1);
      long long zn = (np - 1) * np / 2 * m;
      long long rm = n - (np * m);
      zn += rm * (rm + 1) / 2;
      cout << sm - zn << endl;
    }
  }
}
