#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, tt;
  cin >> tt;
  for (t = 1; t <= tt; t++) {
    long long int n, m, ans, temp, a;
    cin >> n >> m;
    temp = (n / (m + 1));
    ans = m;
    ans = (m * temp * (temp + 1)) / 2;
    temp = n - temp;
    ans += temp * (temp + 1) / 2;
    cout << ans << endl;
  }
  return 0;
}
