#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll cou(ll n) { return ((n + 1) * n) / 2; }
int main() {
  ll t;
  cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    m++;
    ll z = (n - m + 1);
    ll x = z / m;
    cout << cou(n) - (z % m) * cou(x + 1) - (m - (z % m)) * cou(x) << "\n";
  }
}
