#include <bits/stdc++.h>
using namespace std;
const long long maxn = 300000 + 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;
    long long t = (n - m) / (m + 1);
    long long z = (n - m) % (m + 1);
    long long ans = (m + 1 - z) * t * (t + 1) / 2;
    ans += z * (t + 1) * (t + 2) / 2;
    ans = n * (n + 1) / 2 - ans;
    cout << ans << '\n';
  }
  return 0;
}
