#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, z = 0, tz = 0, a = 0, b = 0;
    cin >> n >> m;
    long long total = n * (n + 1) / 2;
    z = n - m;
    a = z / (m + 1);
    b = z % (m + 1);
    tz = (m + 1) * a * (a + 1) / 2 + (a + 1) * b;
    cout << total - tz;
    cout << "\n";
  }
  return 0;
}
