#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T t) {
  for (const auto &it : t) cout << it << ' ';
  cout << "\n";
}
const double Pi = acos(-1.0);
const int Mod = 1e9 + 7;
const int Eps = 1e-9;
const int Inf = 1 << 28;
const int Maxx = 1e5 + 10;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    long long n, m;
    cin >> n >> m;
    long long tot = n * (n + 1) / 2;
    long long zpg = (n - m) / (m + 1);
    tot =
        tot - (m + 1) * (zpg * (zpg + 1) / 2) - (zpg + 1) * ((n - m) % (m + 1));
    cout << tot << "\n";
  }
  return 0;
}
