#include <bits/stdc++.h>
using namespace std;
const long long D = 0;
const long long N = 1e5 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 7;
const double eps = 1e-9;
long long num(long long x) { return x * (x + 1) / 2; }
int solve() {
  long long n, m;
  cin >> n >> m;
  long long interval = m + 1;
  long long cnt0 = n - m;
  long long ans = 0;
  ans += num(n);
  ans -= (cnt0 % interval) * num(cnt0 / interval + 1);
  ans -= (interval - cnt0 % interval) * num(cnt0 / interval);
  cout << ans << '\n';
  return 0;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  if (D) freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
