#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = -1e-2;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const long long mod = 1e9 + 7;
const int MX = INT_MAX;
const int N = 1e6 + 5;
void Open() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Open();
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long numOfZeros = n - m, numOfGroubs = m + 1;
    long long k = numOfZeros / numOfGroubs;
    long long rem = numOfZeros % numOfGroubs;
    cout << n * (n + 1) / 2 - k * (k + 1) / 2 * numOfGroubs - (k + 1) * rem
         << "\n";
  }
}
