#include <bits/stdc++.h>
using namespace std;
int t;
string st;
int r, p, s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long ans = (long long)n * (long long)(n + 1) / 2LL;
    int z = n - m;
    int k = z / (m + 1);
    ans -= (long long)(m + 1) * (long long)k * (long long)(k + 1) / 2LL;
    ans -= (long long)(z % (m + 1)) * (long long)(k + 1);
    printf("%lld\n", ans);
  }
}
