#include <bits/stdc++.h>
using namespace std;
vector<long long int> g[100005];
long long int vis[100005];
vector<double> ans;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int p = (n * (n + 1)) / 2;
    long long int k = (n - m) / (m + 1);
    long long int x = (n - m) % (m + 1);
    long long int y = m + 1 - x;
    long long int l = y * (k * (k + 1)) / 2;
    long long int l2 = x * ((k + 1) * (k + 2)) / 2;
    p = p - l - l2;
    cout << p << endl;
  }
  return 0;
}
