#include <bits/stdc++.h>
using namespace std;
const long long mx = 105;
const long long mod = 998244353;
const long long maxn = 1e17;
void solve() {
  long long n, m, i, j, k;
  cin >> n >> m;
  long long res = 0;
  long long ns = m + 1;
  long long ng = (n - m) / ns;
  long long cv = ng * (ng + 1) / 2;
  res += cv * (ns);
  res += ((n - m) % ns) * (ng + 1);
  res = n * (n + 1) / 2 - res;
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
