#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    ll ans = (n + 1) * n / 2;
    ll cnt = (n - m) / (m + 1);
    ll rest = (n - m) % (m + 1);
    ans -=
        rest * (cnt + 1) * (cnt + 2) / 2 + (m + 1 - rest) * (cnt + 1) * cnt / 2;
    cout << ans << endl;
  }
  return 0;
}
