#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infll = 1e14 + 10;
const int maxn = 100 + 10;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long sum = n * (n + 1) / 2;
  long long num_zero = n - m;
  long long num_seg = m + 1;
  long long len = num_zero / num_seg;
  long long more = num_zero % num_seg;
  long long num_sub1 = len * (len + 1) / 2;
  long long num_sub2 = (len + 1) * (len + 2) / 2;
  sum -= num_sub1 * (num_seg - more);
  sum -= num_sub2 * more;
  cout << sum << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
