#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100000 + 500;
const long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (m == 0) {
      cout << "0\n";
      continue;
    }
    if ((n - m) < (n + 1) / 2) {
      long long ans = n * (n + 1) / 2 - (n - m);
      cout << ans << '\n';
      continue;
    }
    long long k = n / (m + 1);
    long long ansp = k * (k + 1) / 2;
    long long ans = n / (k + 1);
    ans *= ansp;
    long long len = n % (k + 1);
    ans += len * (len + 1) / 2;
    ans = n * (n + 1) / 2 - ans;
    cout << ans << '\n';
  }
  return 0;
}
