#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int T;
inline int Abs(int a) { return (a < 0 ? -a : a); }
long long n, m;
int main() {
  ios::sync_with_stdio(0);
  cin >> T;
  while (T--) {
    cin >> n >> m;
    long long ans = n * (n - 1LL) / 2LL + n;
    long long k = (n - m) / (m + 1LL);
    ans -= (k * (k + 1LL) / 2LL) * (m + 1LL);
    long long l = (n - m) % (m + 1LL);
    ans -= (k + 1LL) * l;
    cout << ans << endl;
  }
  return 0;
}
