#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long tot = (n * (n + 1)) / 2;
    n -= m;
    long long divi = m + 1;
    long long lower = n / divi;
    long long upper = (n + divi - 1) / divi;
    long long qupper = n % divi;
    long long qlower = divi - qupper;
    cout << tot - (qlower * ((lower * (lower + 1)) / 2)) -
                (qupper * ((upper * (upper + 1)) / 2))
         << '\n';
  }
}
