#include <bits/stdc++.h>
using namespace std;
void Fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void File() {}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long nPr(int n, int r) {
  long long solve = 1;
  for (int i = (n - r + 1); i <= n; i++) {
    solve *= i;
    solve %= 1000000007;
  }
  return solve;
}
bool valid(string s) {
  for (int i = 1; i < s.size(); i++) {
    if (s[i] <= s[i] - 1) return 0;
  }
  return 1;
}
int main() {
  File(), Fast();
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long sum = (n * (n + 1)) / 2;
    n -= m;
    long long x, y = 0;
    x = n / (m + 1), y = x + 1;
    long long xx = (m + 1) - n % (m + 1), yy = n % (m + 1);
    cout << sum - (xx * ((x * (x + 1)) / 2) + yy * (y * (y + 1) / 2)) << "\n";
  }
}
