#include <bits/stdc++.h>
using namespace std;
long long n, m;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long ntest;
  cin >> ntest;
  while (ntest--) {
    cin >> n >> m;
    long long no_of_0 = n - m;
    long long q = no_of_0 / (m + 1), r = no_of_0 % (m + 1);
    long long ans = n * (n + 1) / 2;
    if (r != 0) {
      ans -= r * (q + 1) * (q + 2) / 2;
      ans -= (m + 1 - r) * (q) * (q + 1) / 2;
    } else {
      ans -= (m + 1) * q * (q + 1) / 2;
    }
    cout << ans << "\n";
  }
}
