#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << '\n';
  err(++it, args...);
}
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 1;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  ;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    ;
    long long tot = n * (n + 1) / 2;
    n = n - m;
    m++;
    long long rem = n % m, x = n / m;
    cout << tot - ((m - rem) * x * (x + 1) / 2 + (x + 1) * (x + 2) * rem / 2)
         << '\n';
  }
}
