#include <bits/stdc++.h>
using namespace std;
long long int cell(long long int a, long long int b) {
  if (a == 0 || b == 0) return 0;
  if (a % b == 0)
    return (a / b);
  else
    return (a / b) + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 0;
  cin >> t;
  while (t--) {
    long long int n, m, k, i, j, p, q, x, y, ans = 0, cnt = 0;
    string s;
    bool flag = false;
    cin >> n >> m;
    long long int z = n - m;
    y = cell(z, m + 1);
    if (y == 0)
      x = 0, p = 0;
    else
      x = z / y, p = z % y;
    cnt += x * y * (y + 1) / 2;
    cnt += p * (p + 1) / 2;
    ans = n * (n + 1) / 2;
    ans = ans - cnt;
    cout << ans << endl;
  }
  return 0;
}
