#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll OO = 1e18;
int di[8] = {0, 0, 1, -1, -1, 1, -1, 1};
int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1};
string ys = "YES", no = "NO";
const int N = 2e5 + 5;
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    ll all = n * (n + 1) / 2;
    ll z = n - m;
    ll tot = z / (m + 1);
    ll rem = z % (m + 1);
    all -= (m + 1 - rem) * (tot) * (tot + 1) / 2;
    all -= (rem) * (tot + 1) * (tot + 2) / 2;
    cout << all << '\n';
  }
}
