#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long tot0 = n - m;
    long long g = m + 1LL;
    long long cg0 = tot0 / g;
    long long sob = tot0 % g;
    long long sub = n * (n + 1LL) / 2LL;
    long long res = sub - g * (cg0) * (cg0 + 1LL) / 2LL - (cg0 + 1LL) * sob;
    cout << res << '\n';
  }
  return 0;
}
