#include <bits/stdc++.h>
using namespace std;
long long int n, m, rs, h, l;
int main() {
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    cin >> n >> m;
    rs = (n * (n + 1)) / 2;
    h = (n / (m + 1));
    h = ((h * (h + 1)) / 2) * ((n - m) % (m + 1));
    l = ((n - m) / (m + 1));
    l = ((l * (l + 1)) / 2) * (m + 1 - ((n - m) % (m + 1)));
    cout << rs - h - l << endl;
  }
  return 0;
}
