#include <bits/stdc++.h>
using namespace std;
long long ans, n, m;
void solve() {
  cin >> n >> m;
  ans = n * (n + 1) / 2;
  long long w = n - m;
  long long a = w / (m + 1), b = w % (m + 1);
  ans = ans - (1 + a) * a / 2 * (m + 1 - b) - b * (1 + a + 1) * (a + 1) / 2;
  cout << ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
